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
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top