+ Reply to Thread
Results 1 to 5 of 5

Hide Rows based on cell color

Hybrid View

jeff.p Hide Rows based on cell color 11-26-2007, 01:47 PM
Simon Lloyd Try this: Sub hide_rows()... 11-26-2007, 01:58 PM
jeff.p Outstanding.. Thanks,... 11-26-2007, 03:33 PM
VBA Noob Try the below but change 4 to... 11-26-2007, 04:45 PM
jeff.p Thank you very much, Mr. Noob... 11-26-2007, 10:47 PM
  1. #1
    Registered User
    Join Date
    08-23-2007
    Posts
    58

    Hide Rows based on cell color

    Hello


    I've created a named Range ("VRange") in column V16:V600

    Within this range I have numerous cells with the color Red.


    I would like to create a button which hides all the rows, within this range, that are non-Red color (Leaving only the Red showing)


    Is there a way to create a macro without using conditional formatting?


    Thanks for any help

    Jeff

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Try this:
    Sub hide_rows()
    Dim Rng As Range
    Dim MyCell As Range
    Set Rng = Range("vrange")
    For Each MyCell In Rng
    If MyCell.Interior.ColorIndex = xlNone Then
    MyCell.EntireRow.Hidden = True
    End If
    Next MyCell
    End Sub
    Not all forums are the same - seek and you shall find

  3. #3
    Registered User
    Join Date
    08-23-2007
    Posts
    58
    Outstanding..


    Thanks, Simon!




    May ask a follow up question?

    If the "VRange" contained various colored cells, but I only wanted to show the green colored ones how could your code be modified to accommodate this...?

    thanks again!

    Jeff

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Try the below but change 4 to your green shade. Use the VBA recorder to found the color index of your shade of green

    Sub hide_rows()
    Dim Rng As Range
    Dim MyCell As Range
    Set Rng = Range("vrange")
         For Each MyCell In Rng
              If Not MyCell.Interior.ColorIndex = 4 Then
                   MyCell.EntireRow.Hidden = True
             End If
         Next MyCell
    End Sub
    VBA Noob
    Last edited by VBA Noob; 12-26-2007 at 12:34 PM.
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  5. #5
    Registered User
    Join Date
    08-23-2007
    Posts
    58
    Thank you very much, Mr. Noob


    worked great!


    Jeff

+ 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