macro to select range of cells...

G

Guest

Guest
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....
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
On 2002-03-08 12:25, Anonymous wrote:
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....
This code will select the entire row where the value in column D is blank (for the range D1:D5).

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

Regards,
 
Upvote 0
Or more simply :-

Sub ThosePeskyEmptyCells()
On Error Resume Next
Range("D1:D5").SpecialCells(xlCellTypeBlanks).EntireRow.Select
On Error GoTo 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,478
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top