+ Reply to Thread
Results 1 to 5 of 5

Macro to hide a series of rows that have no 'color' formatting

Hybrid View

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Macro to hide a series of rows that have no 'color' formatting

    I am a casual Excel user and have dabbled in macro writing 10 years ago. I have a current problem where I am identifying certain data by adding different colors to a range of cells. I need a macro that will 'hide' all rows that do not contain any colored cells. Anyone have any suggestions?

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Macro to hide a series of rows that have no 'color' formatting

    Hello there,

    The below code should work for you:

    Dim LR As String, i As Long  'declare variables
    LR = Range("A6555").End(xlUp).Row  ' Set Lr equal to the last row in column A that contains a value
    
    For i = 1 To LR   'i is equal to numbers 1 through the last row number (loop through i)
        If Rows(i & ":" & i).Interior.ColorIndex = xlNone Then   'if the current row number in the loop contains no colored cells then
            Rows(i & ":" & i).RowHeight = 0   'hide the row
        End If
    Next i

  3. #3
    Registered User
    Join Date
    09-11-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Macro to hide a series of rows that have no 'color' formatting

    I applied the code as follows and it only hid the first row with no color, not all of the rows. I am searching rows 4 to 89.


    Dim LR As String, i As Long 'declare variables
    LR = Range("B89").End(xlUp).Row ' Set Lr equal to the last row in column A that contains a value

    For i = 1 To LR 'i is equal to numbers 1 through the last row number (loop through i)
    If Rows(i & ":" & i).Interior.ColorIndex = xlNone Then 'if the current row number in the loop contains no colored cells then
    Rows(i & ":" & i).RowHeight = 0 'hide the row
    End If
    Next i
    End Sub

  4. #4
    Registered User
    Join Date
    09-11-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Macro to hide a series of rows that have no 'color' formatting

    I figured it out! I added 'For i = 4 To 89' and it worked to hide all rows with no colored cells!

  5. #5
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Macro to hide a series of rows that have no 'color' formatting

    Hello there,

    That will work as long as your data remains no more than 89 rows. If you want it to be able to be used in the instance you add more rows

    Dim LR As String, i As Long 'declare variables
    LR = Range("B6555").End(xlUp).Row ' Set Lr equal to the last row in column A that contains a value
    
    For i = 1 To LR 'i is equal to numbers 1 through the last row number (loop through i)
    If Rows(i & ":" & i).Interior.ColorIndex = xlNone Then 'if the current row number in the loop contains no colored cells then
    Rows(i & ":" & i).RowHeight = 0 'hide the row
    End If
    Next i
    End Sub
    You code would look like above, I've highlighted the change in the code in red. Just for future reference you use B6555 as a started because the End(xlup) code basically says to start at Row 6555 and find the first cell before row 6555 in column B that has data in it and return that row number.

    Please don't forget this thread solved and maybe give a little star tap if I've helped.

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1