在cnt1的部分,我试图使用一个整数(称为A),我将在循环中增加,因此它从shtSheet1变为shtSheet5。在我的代码中,我有shtSheet $ A来澄清我想要做什么,但我不知道visual basic是否允许这种连接。我只习惯编码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
我更新了我的完整宏,因此更容易理解。它比较了两张纸,我想修改它以比较5张纸,但是以特定的方式,只比较纸张1-2,2-3,3-4,4-5。
我的想法是使用A和B以及goto来做我想做的事。