获取 2 个不同工作表的行数和列数后,在 vlookup 比较中出现问题。结果中有 1 个不匹配
Issue in vlookup comparison after getting rows and columns count of 2 different sheets. There is 1 mismatch in the results
在我的 vba 脚本中,我从 2 个不同的工作表中获取行数和列数,并使用 Vlookup 将这些值与每个工作表进行比较。比较结果正在更新,如未找到和已找到。而 1 个结果不匹配。谁能帮我解决这个问题?
ExpectedDataRowCount = Sheets("Sheet1").Cells.SpecialCells(xlLastCell).Row
ExpectedDataColumnCount = Sheets("Sheet1").Cells.SpecialCells(xlLastCell).Column
ExpectedSrc = "R2C2:R" & ExpectedDataRowCount & "C" & ExpectedDataColumnCount
ActualDataRowCount = Sheets("Sheet2").Cells.SpecialCells(xlLastCell).Row
ActualDataColumnCount = Sheets("Sheet2").Cells.SpecialCells(xlLastCell).Column
Actualsrc = "R1C1:R" & ActualDataRowCountPlusone & "C" & ActualDataColumnCount
ActiveCell.FormulaR1C1 = _
"=IF(ISNA(VLOOKUP([Actual_Value.xls]Sheet2!" & Actualsrc & _
",[Expected_Value.xlsx]Sheet1!" & ExpectedSrc & _
",1,FALSE)),""Not Found"",""Found"")"
我认为这种情况会受益于使用 IF 语句而不是依赖 excel 公式。
你应该更换你的:
ActiveCell.FormulaR1C1 = _
"=IF(ISNA(VLOOKUP([Actual_Value.xls]Sheet2!" & Actualsrc &_
",[Expected_Value.xlsx]Sheet1!" & ExpectedSrc & ",1,FALSE)),""Not Found"",""Found"")"
作者:
For column = 1 to ActualDataColumnCount
For row = 1 to ActualDataRowCount
For column1 = 1 to ExpectedDataColumnCountFor
row1 = 1 to ExpectedDataRowCount
IF Application.Workbooks("Actual_Value").Worksheets("Sheet2").Cells(row,column)_
= Application.Workbooks("Expected_Value").Worksheets("Sheet1").Cells(row1,column1) Then
ActiveCell.Value = "Found"
Else
ActiveCell.Value = "Not Found"
End If
next row1
next column1
next row
next column
在我的 vba 脚本中,我从 2 个不同的工作表中获取行数和列数,并使用 Vlookup 将这些值与每个工作表进行比较。比较结果正在更新,如未找到和已找到。而 1 个结果不匹配。谁能帮我解决这个问题?
ExpectedDataRowCount = Sheets("Sheet1").Cells.SpecialCells(xlLastCell).Row
ExpectedDataColumnCount = Sheets("Sheet1").Cells.SpecialCells(xlLastCell).Column
ExpectedSrc = "R2C2:R" & ExpectedDataRowCount & "C" & ExpectedDataColumnCount
ActualDataRowCount = Sheets("Sheet2").Cells.SpecialCells(xlLastCell).Row
ActualDataColumnCount = Sheets("Sheet2").Cells.SpecialCells(xlLastCell).Column
Actualsrc = "R1C1:R" & ActualDataRowCountPlusone & "C" & ActualDataColumnCount
ActiveCell.FormulaR1C1 = _
"=IF(ISNA(VLOOKUP([Actual_Value.xls]Sheet2!" & Actualsrc & _
",[Expected_Value.xlsx]Sheet1!" & ExpectedSrc & _
",1,FALSE)),""Not Found"",""Found"")"
我认为这种情况会受益于使用 IF 语句而不是依赖 excel 公式。
你应该更换你的:
ActiveCell.FormulaR1C1 = _
"=IF(ISNA(VLOOKUP([Actual_Value.xls]Sheet2!" & Actualsrc &_
",[Expected_Value.xlsx]Sheet1!" & ExpectedSrc & ",1,FALSE)),""Not Found"",""Found"")"
作者:
For column = 1 to ActualDataColumnCount
For row = 1 to ActualDataRowCount
For column1 = 1 to ExpectedDataColumnCountFor
row1 = 1 to ExpectedDataRowCount
IF Application.Workbooks("Actual_Value").Worksheets("Sheet2").Cells(row,column)_
= Application.Workbooks("Expected_Value").Worksheets("Sheet1").Cells(row1,column1) Then
ActiveCell.Value = "Found"
Else
ActiveCell.Value = "Not Found"
End If
next row1
next column1
next row
next column