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.


ColumnAColumnB
05255088-0f15-48f1-a65e-affb6d583d351373064224475
05255088-0f15-48f1-a65e-affb6d583d351373064224475
05384219-f4ad-44de-9efc-d6526ad169411373064223701
05384219-f4ad-44de-9efc-d6526ad169411373064223701
0539a867-1272-462d-ab34-fe3af4d0aa8b1373064221218
0539a867-1272-462d-ab34-fe3af4d0aa8b1373064221218
0539a867-1272-462d-ab34-fe3af4d0aa8b1373064221218
0539a867-1272-462d-ab34-fe3af4d0aa8b1373064221218

<tbody>
</tbody>


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)

05255088-0f15-48f1-a65e-affb6d583d351373064224475
05255088-0f15-48f1-a65e-affb6d583d351373064224475
05384219-f4ad-44de-9efc-d6526ad169411373064223701
05384219-f4ad-44de-9efc-d6526ad1694112345
0539a867-1272-462d-ab34-fe3af4d0aa8b1373064221218
0539a867-1272-462d-ab34-fe3af4d0aa8b1373064221218
0539a867-1272-462d-ab34-fe3af4d0aa8b9876543
0539a867-1272-462d-ab34-fe3af4d0aa8b9876543

<tbody>
</tbody>


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

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
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,215,972
Messages
6,128,026
Members
449,414
Latest member
sameri

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