当前,我能够比较同一文件中的不同工作表。如果将Sheet3移到另一个文件(例如:File2),如何实现?并且Sheet1 B2将返回“通过”或“失败”,取决于内容匹配与否。
文件1-Sheet1
文件1-Sheet2
文件1-Sheet3
system preferences -> security & privacy -> privacy -> {unlock the padlock putting my admin password} -> {locate, uncheck and recheck my executable from the list}
答案 0 :(得分:0)
Workbooks.Open
Sheet3
类似这样的东西:
Sub Compare()
Dim dataLength As Long
dataLength = 100
Sheet1.Range("B2").Value = "Pass"
'open the workbook
Dim ExternalWb As Workbook
Set ExternalWb = Workbooks.Open(Filename:="C:\your folder\your file.xlsx")
'get the sheet
Dim ExternalSheet As Worksheet
Set ExternalSheet = ExternalWb.Worksheets("Sheet3")
Dim i As Long
For i = 1 To dataLength
If ExternalSheet.Cells(1, i) <> Sheet2.Cells(i, 1) Then
Sheet1.Range("B2").Value = "Fail"
Exit For
End If
Next i
End Sub