In the part of cnt1, I'm trying to use an integer (called A) that I'll increase in a loop so it goes from shtSheet1 to shtSheet5. In my code, I have shtSheet$A to clarify what I want to do but I don't know if visual basic allow that kind of concatenation. I'm only used to coding bash Scripts.
Sub RunCompare()
Call compareSheets("PROD", "OSA", "UAT", "INT", "TEST")
End Sub
Sub compareSheets(shtSheet1 As String, shtSheet2 As String, shtSheet3 As String, shtSheet4 As String, shtSheet5 As String)
Dim c As Integer, j As Integer, i As Integer, mydiffs As Integer, cnt1 As Integer, cnt2 As Integer, A As Integer, B As Integer
Dim noexist As Integer
A = 1
B = 2
cnt1 = Worksheets(shtSheet).Cells.SpecialCells(xlCellTypeLastCell).Row
cnt2 = Worksheets(shtSheetB).Cells.SpecialCells(xlCellTypeLastCell).Row
'For each cell in sheet2 that is not the same in Sheet1, color it yellow
LoopStart:
For i = 1 To cnt2
For j = 1 To cnt1
If ActiveWorkbook.Worksheets(shtSheet2).Cells(i, 1).Value = ActiveWorkbook.Worksheets(shtSheet1).Cells(j, 1).Value Then
For c = 2 To 22
If Not ActiveWorkbook.Worksheets(shtSheetB).Cells(i, c).Value = ActiveWorkbook.Worksheets(shtSheet2).Cells(j, c).Value Then
ActiveWorkbook.Worksheets(shtSheet2).Cells(i, c).Interior.Color = vbYellow
mydiffs = mydiffs + 1
End If
Next
Exit For
End If
If j = cnt1 Then
ActiveWorkbook.Worksheets(shtSheet2).Cells(i, 1).Interior.Color = vbRed
End If
Next
Next
A = A + 1
B = B + 1
If A <= 4 Then
GoTo LoopStart
End If
End Sub
Sub Clear_Highlights_this_Sheet()
ActiveSheet.UsedRange. _
Interior.ColorIndex = xlNone
End Sub
Sub Clear_Highlights_All_Sheets()
Dim sht As Worksheet
For Each sht In sheets
sht.UsedRange.Interior.ColorIndex = xlNone
Next
End Sub
I updated my full macro so it is easier to understand. It compares 2 sheets and I would like to modify it to compare 5 sheets but in a specific way, only comparing the sheets 1-2, 2-3, 3-4, 4-5.
My idea was to use the A and B and a goto to do what I want.