+ Reply to Thread
Results 1 to 8 of 8

Thread: Cells with same value, rows with same color. Uneven list

  1. #1
    Registered User
    Join Date
    07-01-2011
    Location
    Italy
    MS-Off Ver
    Excel 2003
    Posts
    17

    Arrow Cells with same value, rows with same color. Uneven list

    Hello,
    I must say you really helped me with my excel issues; anyway I could not find answer to this question:
    I have table structurated as the follow:

    1 data1 data1...
    1 data1 data1...
    1 data1 data1...
    2 data2 data2...
    2 data2 data2...
    3 data3 data3...
    3 data3 data3...
    3 data3 data3...
    3 data3 data3...
    ....
    and so on.
    So in first coloumn I have a value identyfing the entry wich correspond to multiple rows. I would like to color the entry and correspondent rows the same, the next entry and its rows with another color and then alternate this colors for the next entries.
    The numbers of rows per entry is not constant i could have 2 rows for an entry and 5 for others.
    Also I have attached an example how what I have and what I want.I hope i made myself understandeable!
    Thanks again!
    Attached Files Attached Files
    Last edited by Macuil0101; 07-04-2011 at 08:00 AM.

  2. #2
    Registered User
    Join Date
    07-01-2011
    Location
    Italy
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Cells with same value, rows with same color. Uneven list

    Is it eventually possible?
    Thanks

  3. #3
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Cells with same value, rows with same color. Uneven list

    check this
    Sub a()
    Dim col
    col = Array(15, 48) 'color indexes
    Dim r As Integer 'row index
    Dim c As Integer 'colour index
    Dim check As String 'checking value
    
    r = 3
    c = 0
    
    check = Cells(r, 3).Value
    Do Until Cells(r, 3).Value = ""
     If Cells(r, 3).Value <> check Then
      c = c + 1
      check = Cells(r, 3).Value
     End If
      
     Rows(r & ":" & r).Interior.ColorIndex = col(c Mod 2) 'set row interior colour
     
     r = r + 1
    Loop
    End Sub
    Best Regards
    MaczaQ

  4. #4
    Registered User
    Join Date
    07-01-2011
    Location
    Italy
    MS-Off Ver
    Excel 2003
    Posts
    17

    Lightbulb Re: Cells with same value, rows with same color. Uneven list

    Quote Originally Posted by maczaq View Post
    check this
    I am sorry but that doesn't seem to work the colors changes not for every entry, also i need to insert the value of the last cell, and i need it be automatic as the macro it is applied by an external app.
    I post here a code a found which divide every entry with border, maybe from that will be possible to construct a color code:
        Set rRange = Range("A3", Range("A65536").End(xlUp))
            For Each rCell In rRange
            If Not IsEmpty(rCell) And _
               Not IsEmpty(rCell.Offset(1, 0)) Then
                With rCell
                    If .Value <> .Offset(1, 0).Value Then
                       With .Resize(1, 18).Borders(xlEdgeBottom)
                            .LineStyle = xlContinuous
                            .Weight = xlMedium
                            .ColorIndex = xlAutomatic
                    End With
                    End If
                End With
            End If
        Next rCell
    Thank you very much for your attention!

  5. #5
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Cells with same value, rows with same color. Uneven list

    I'm a bit confused because I think this code works in way you want.

    Please check attached example. Now is sensitive for changes in Sheet1

    Best Regards
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    07-01-2011
    Location
    Italy
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Cells with same value, rows with same color. Uneven list

    Quote Originally Posted by maczaq View Post
    I'm a bit confused because I think this code works in way you want.

    Please check attached example. Now is sensitive for changes in Sheet1

    Best Regards
    It's very strange because on my data doesn't work while it does in the example. Perhaps because in the first column the values are alphanumeric instead of just numbers?

  7. #7
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Cells with same value, rows with same color. Uneven list

    No it is not a reason that you have other formatting of cell because there is simply comparishion of cell value.

    (You wrote "first column") - in example first column is "C" and here is part of code testing values in column C:
    check = Cells(r, 3).Value 'here 3 is column index
    Do Until Cells(r, 3).Value = "" 'and here
     If Cells(r, 3).Value <> check Then 'and here
      c = c + 1
      check = Cells(r, 3).Value 'and here
    make sure that your "first column" is C or change that 3 into correct column index and should work with your data.

    Best Regards

  8. #8
    Registered User
    Join Date
    07-01-2011
    Location
    Italy
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Cells with same value, rows with same color. Uneven list

    Quote Originally Posted by maczaq View Post
    (You wrote "first column") - in example first column is "C" and here is part of code testing values in column C
    Thank you so much! Now it works! You have to forgive me as I am very new to VBA!
    One last request, if possible, is to make it just for the first 12 columns.
    Last edited by Macuil0101; 07-04-2011 at 08:08 AM.

+ 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.2.0