Change colours at each change in row data

Chico

New Member
Joined
Nov 17, 2005
Messages
5
:LOL:
Hi - I have just started using macros and wandered how I could get the colour of a row to change to yellow at each change in name.
EG I have a list of names and at each change in name i want to highlight the row in yellow so that i can identify that the company name has changed
would really appreciate any help ... thanks
 

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
Code:
Sub test()
    myrow = 1    ' start in row 1
    myvalue = Cells(myrow, 1).Value   ' cell(1,1) = A1
    '- go down column A
    While Cells(myrow, 1) <> ""
        If Cells(myrow, 1).Value <> myvalue Then
            Cells(myrow, 1).EntireRow.Interior.ColorIndex = 6
            myvalue = Cells(myrow, 1).Value
        End If
        myrow = myrow + 1
    Wend
End Sub
 

Chico

New Member
Joined
Nov 17, 2005
Messages
5
Sorry I'm a bit confused :oops:

The column I want to change is Column H & Row is H4.
So do I change like this
myrow=4 'start in row4
myvalue = Cells(myrow, 4).Value ' cell(H4,H500) = A1 ??????
'- go down column H
While Cells(myrow, 4) <> ""
If Cells(myrow, 4).Value <> myvalue Then
Cells(myrow, 4).EntireRow.Interior.ColorIndex = 6
myvalue = Cells(myrow, 4).Value
End If
myrow = myrow + 4
Wend
End Sub
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,222
Have you considered not using VBA, and simple Conditional Formatting. Try this, select from cell H5 down to as far as you think you will have data in column H. Then with that range selected with H5 as the active cell, click on Format > Conditional Formatting, select "Formula is" from the drop-down, and in the field to the right of that enter
=H5<>H4

Or, for the entire row, click the "5" row header and drag your mouse down to the row header that will be the last row of data. Now given the preceding steps above, in the Conditional Formatting dialog, enter the formula
=$H5<>$H4

Click the Format button, patterns tab, select the yellow square from the color palette, click OK, OK and that should do it.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,670
Messages
5,573,554
Members
412,537
Latest member
Mohamed_5966
Top