Cell comparison multiple sheets

mbpress01

New Member
Joined
Dec 30, 2017
Messages
20
I have a few sheets that I need to compare cells in one column in sheet1 vs one column in sheet2. If match is made (with an "alert" match also) , the code colors the cell. The code taken from this site is as follows:

VBA Code:
Sub Compare()

Dim w1 As Worksheet
Dim w2 As Worksheet
Dim c As Range
Dim a As Range

Set w1 = Sheets("sheet1")
Set w2 = Sheets("sheet2")

With w1
   For Each c In .Range("A1:A100")
   Set a = w2.Columns(1).Find(c.Value, LookAt:=xlWhole)
   If Not a Is Nothing Then
      If w1.Cells(c.Row, 1).Value <> w2.Cells(a.Row, 1).Value And .Cells(c.Row, 2) = "ALERT" Then
         w2.Cells(a.Row, 1).Interior.ColorIndex = 3
      End If
   End If
  Next c
End With

End Sub

As you can see, the goal is to run a comparison on column 1 sheet1 against column 1 in sheet2. It works perfectly but what I need to do is to run the same comparison against sheet 3, 4, 5 6, etc etc. I know there is a way to do this through an array but I can't figure it out. I can copy the code multiple times and just change the w2 reference to w2 = sheet3, w2 = sheet4 etc but that is inefficient. I am not clear how to loop the array for each sheet.

Thanks for the help in advance and this site has been hugely helpful in my daily work.
 
Sorry about that fluff. Sometimes you think you know what you are asking for but until you see the solution you realize you didn’t. So again, apologies but this is exactly what I needed and now I can apply that technique in other places also. You are the man and thx again for all the help. Problem solved.
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,569
Members
452,652
Latest member
eduedu

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