+ Reply to Thread
Results 1 to 4 of 4

Interior Colour Selection Query

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro Plus 2021
    Posts
    424

    Interior Colour Selection Query

    Is it possible to have a macro scan the range A2:AF300 and if any cells have an interior color index number of 33 i.e.

        With Selection.Interior
            .ColorIndex = 33
            .Pattern = xlSolid
        End With
    If it finds any cells then select the range A:AF of the row the cell is in and colour the whole row using the above code?

    Thanks

    Tim.
    Last edited by timbo1957; 10-18-2011 at 05:10 AM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Interior Colour Selection Query

    Sub ColorRowIfIC33()
      Dim cell As Range, rCell As Range
      For Each rCell In Range("A2:AF300").Rows
        For Each cell In rCell.Cells
          If cell.Interior.ColorIndex = 33 Then
            rCell.Interior.ColorIndex = 33
            GoTo NextrCell
          End If
        Next cell
    NextrCell:
      Next rCell
    End Sub

  3. #3
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro Plus 2021
    Posts
    424

    Re: Interior Colour Selection Query

    This works but in the wrong way.

    Sub ColorRowIfIC33()
      Dim cell As Range, rCell As Range
      For Each rCell In Range("A2:AF300").Rows
        For Each cell In rCell.Cells
          If cell.Interior.ColorIndex = 33 Then
            rCell.Interior.ColorIndex = 33
            GoTo NextrCell
          End If
        Next cell
    NextrCell:
      Next rCell
    End Sub

    I need it to start in row 2 and if any cell in A2:AF2 has an Interior Colour.Index of 33 then colour the whole of row 2 Interior Colour.Index of 33.

    Then go to Row 3 and do the same.

    What it is doing at the moment is coloring every row if any row in the range has a Interior Colour.Index of 33.

    In addition the range is variable so maybe from A2 to the bottom of the data would be better.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Interior Colour Selection Query

    Quote Originally Posted by timbo1957 View Post
    If it finds any cells then select the range A:AF of the row the cell is in and colour the whole row using the above code?
    That is what Kenneth's code does.
    Everyone who confuses correlation and causation ends up dead.

+ 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