![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
anyone know how to create a macro that would do the following:
within a certain range of cells (ex- D1:D5), for those cells that are empty, they and their entire rows are selected/highlighted. So, for example, if D1, D2, D3, & D4 had text and or numbers in them, and D5 was empty, the macro would select/highlight the entire row 5. Thanks.... |
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
Code:
Sub ThosePeskyEmptyCells()
Dim HighlightRange As Range
On Error GoTo ErrorHandler
For Each c In Range("D1:D5")
If c.Value = "" Then
If HighlightRange Is Nothing Then
Set HighlightRange = Range(c.Address)
Else
Set HighlightRange = Union(HighlightRange, _
Range(c.Address))
End If
End If
Next c
HighlightRange.EntireRow.Select
Exit Sub
ErrorHandler:
MsgBox ("No blank cells found")
End Sub
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
|
|
|
#3 |
|
Guest
Posts: n/a
|
thanks man, I'm going to give it a try!
|
|
|
|
#4 |
|
Join Date: Feb 2002
Posts: 12
|
Or more simply :-
Sub ThosePeskyEmptyCells() On Error Resume Next Range("D1:D5").SpecialCells(xlCellTypeBlanks).EntireRow.Select On Error GoTo 0 End Sub |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|