Highlight Cell when Row data changes from previous Row

3gswish

New Member
Joined
Apr 28, 2011
Messages
29
Hi everyone,

I have some very basic scripting skills but they don't yet translate well to VBA so would very much appreciate the benefit of your knowledge.

I have a spreadsheet with over 6k rows, each with over 30 columns.

My focus is in 2 columns. ColumnA is formatted as General, ColumnB as Number.


[TABLE="class: grid, width: 425"]
<tbody>[TR]
[TD]ColumnA[/TD]
[TD]ColumnB[/TD]
[/TR]
[TR]
[TD]05255088-0f15-48f1-a65e-affb6d583d35[/TD]
[TD="align: right"]1373064224475[/TD]
[/TR]
[TR]
[TD]05255088-0f15-48f1-a65e-affb6d583d35[/TD]
[TD="align: right"]1373064224475[/TD]
[/TR]
[TR]
[TD]05384219-f4ad-44de-9efc-d6526ad16941[/TD]
[TD="align: right"]1373064223701[/TD]
[/TR]
[TR]
[TD]05384219-f4ad-44de-9efc-d6526ad16941[/TD]
[TD="align: right"]1373064223701[/TD]
[/TR]
[TR]
[TD]0539a867-1272-462d-ab34-fe3af4d0aa8b[/TD]
[TD="align: right"]1373064221218[/TD]
[/TR]
[TR]
[TD]0539a867-1272-462d-ab34-fe3af4d0aa8b[/TD]
[TD="align: right"]1373064221218[/TD]
[/TR]
[TR]
[TD]0539a867-1272-462d-ab34-fe3af4d0aa8b[/TD]
[TD="align: right"]1373064221218[/TD]
[/TR]
[TR]
[TD]0539a867-1272-462d-ab34-fe3af4d0aa8b[/TD]
[TD="align: right"]1373064221218[/TD]
[/TR]
</tbody>[/TABLE]


I need your assistance with VBA code that will Fill the cell in ColumnB if it changes within the same ColumnA data.


So the output would end up like this. (Although the cell would be filled, not the text turned red)

[TABLE="class: grid, width: 425"]
<tbody>[TR]
[TD]05255088-0f15-48f1-a65e-affb6d583d35[/TD]
[TD="align: right"]1373064224475[/TD]
[/TR]
[TR]
[TD]05255088-0f15-48f1-a65e-affb6d583d35[/TD]
[TD="align: right"]1373064224475[/TD]
[/TR]
[TR]
[TD]05384219-f4ad-44de-9efc-d6526ad16941[/TD]
[TD="align: right"]1373064223701[/TD]
[/TR]
[TR]
[TD]05384219-f4ad-44de-9efc-d6526ad16941[/TD]
[TD="align: right"]12345[/TD]
[/TR]
[TR]
[TD]0539a867-1272-462d-ab34-fe3af4d0aa8b[/TD]
[TD="align: right"]1373064221218[/TD]
[/TR]
[TR]
[TD]0539a867-1272-462d-ab34-fe3af4d0aa8b[/TD]
[TD="align: right"]1373064221218[/TD]
[/TR]
[TR]
[TD]0539a867-1272-462d-ab34-fe3af4d0aa8b[/TD]
[TD="align: right"]9876543[/TD]
[/TR]
[TR]
[TD]0539a867-1272-462d-ab34-fe3af4d0aa8b[/TD]
[TD="align: right"]9876543[/TD]
[/TR]
</tbody>[/TABLE]


So it's pretty basic. If we simply remember the first ColumnA and ColumnB data, go to the next row, if ColumnA is the same, then ColumnB should be the same. If it's not, then fill with red, go to the next row, repeat. if ColumnA changes, remember the new pair, go to the next row and compare again.


I've thought about this from a scripting perspective, and imagine that something like this would do the job:

Code:
sub FindBadTermID ()
     Dim row As Integer
     Dim dataA as string, dataB as string
     Set row = 2

     newColumnALoop
          Set dataA = A(row), dataB=B(row)                         # Get the first pair in a new ColumnA group
          Set row=row+1
               testColunBLoop
                  if A(row) = Blank, end
                  if A(row) != dataA, goto newColumnALoop     # If it's a new ColumnA group, go back and get first pair
                  if B(row) != dataB, fill B(row)=red                # If ColumnB is different that ColumnB of the first pair, make the cell red
                  Set row=row+1
                  goto testColumnBLoop
   
End Sub


I've gotten a start on changing the script to VBA, but am now strugging. Would you please take a look and give me your thoughts and code suggestions?

Thank you very much!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
3gswish,

There is a lot of good information in the list.

You are very welcome. Glad I could help again.
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,111
Members
452,302
Latest member
TaMere

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