macro to select range of cells...
macro to select range of cells...
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: macro to select range of cells...

  1. #1
    Guest

    Default

     
    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. #2
    MrExcel MVP Barrie Davidson's Avatar
    Join Date
    Feb 2002
    Location
    Winnipeg
    Posts
    2,330
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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,
    Barrie Davidson

    "You're only given a little spark of madness. You mustn't lose it." - Robin Williams

  3. #3
    Guest

    Default

    thanks man, I'm going to give it a try!

  4. #4

    Join Date
    Feb 2002
    Posts
    12
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Or more simply :-

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

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com