+ Reply to Thread
Results 1 to 2 of 2

Highlight rows with same colors if cells (Column G) share the same content

  1. #1
    Registered User
    Join Date
    10-09-2008
    Location
    London
    Posts
    1

    Highlight rows with same colors if cells (Column G) share the same content

    Hello everyone,

    I would appreciate if anyone can help me with this problem -

    I'd like to highlight rows with same content (in cells) in column G with the same color (could be random) -

    1. if cells have the same content, the rows should have the same color
    2. colors should be differnt
    3. for rows that only have blank cells, rows should be left uncolored


    eg
    G
    row1 apple
    row2 pear
    row3
    row4 pear
    row5 apple


    row1 and 5 should be highlighted with a color and row 2 and 4 should be highlighted with another color;
    row3 will be left blank.

    ========================================================

    I have written something and would appreciate if you could help me debug it


    Thank you very much!!!

    Sub colours()

    Dim I As Integer
    Dim j As Integer

    For I = 3 To 65536
    If Cells(I, "N").Value <> "" Then For j = 1 To 65536 And j < I
    If Cells(I, "N").Value = Cells(j, "N").Value Then Cells(I, "N").EntireRow.Interior.ColorIndex = j

    Exit Function

    Else: Next j

    End If

    For I = 3 To 65536
    If Cells(I, "N").Value <> "" Then For j = 1 To 65536 And j < I
    If Cells(I, "N").Value <> Cells(j, "N").Value Then Cells(I, "N").EntireRow.Interior.ColorIndex = I


    Next I

    End Sub

  2. #2
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    Please use code tags.

    Your code checks every single cell in the column - and checks it against every single row aswell - this seems a somewhat clunky way of doing it...

    Why not sort the data and just colour it in batches? You could then loop through in sections and only change the colour when you hit a new entry in column G?

    If you wanted to retain the order you could add a "sort column" numbered 1 - end of rows and re-sort your data by this column after colouring.

    Better approach?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy Cells Matching ID from Diff. Column?
    By Maus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2008, 02:02 PM
  2. Combine rows within column ref another column
    By TheLostBoy in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 09-18-2008, 02:27 PM
  3. Aliging column data from different rows
    By Legend_Killer in forum Excel General
    Replies: 1
    Last Post: 04-30-2008, 09:51 AM
  4. Number of rows where two column cells have same value ?
    By eagles396 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2007, 09:47 AM
  5. Highlight cells with color when scrolling cells
    By chin_un_len in forum Excel General
    Replies: 3
    Last Post: 02-12-2007, 01:47 PM

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