Excel/Using a macro to highlight a range
I am writing a macro, and part of it needs to highlight a range of empty cells in column P, so that these rows can then be grouped. The data in column P will always begin in cell P6, and can end anywhere between P8 and P35. A new set of data begins in cell P36, and I need to highlight any empty cells inbetween P6 and P36. This empty range is not fixed, and will probably be different each time I run the macro. However, the last cell of the empty range will always be P35. I have tried various combinations of shift, end, down, but cant seem to get the correct range highlighted.
Do you know the code I should be using?
Dim r as Range
Set r = Nothing
On Error Resume Next
set r = Range("P6:P35").SpecialCells(xlBlanks)
On Error goto 0
if not r is nothing then
r.interior.ColorIndex = 3
that would make the background of the empty cells red as an example. (the cells must actually be empty)
does that work for you?
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here