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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

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,270
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,018
Messages
5,834,973
Members
430,330
Latest member
drAli77

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
Top