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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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,516
Messages
6,119,978
Members
448,934
Latest member
audette89

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