我需要动态选择两个Excel工作表的范围,并逐行进行比较并使用excel VBA宏在报表单中将其打印为真或假 . 请帮助.. VBA Macro to compare all cells of two Excel files此链接很有帮助,但我想要动态选择范围,还需要在比较表中打印一些TRUE / FALSE .
我确实想要将工作表加载到variant数组,然后遍历它们以快速执行代码 .
注意 - 请假设需要比较的两个工作表包含相同的行数并进行排序 .
For iRow = LBound(varSheetA, 1) To UBound(varSheetA, 1)
For iCol = LBound(varSheetA, 2) To UBound(varSheetA, 2)
If varSheetA(iRow, iCol) = varSheetB(iRow, iCol) Then
' Cells are identical.
' i want to go to the exact cell in Comparison sheet and type TRUE Else
' Cells are different.
' i want to go to the exact cell in Comparison sheet and type FALSE
End If
Next iCol
Next iRow
1 回答
这是一个例子 . 示例代码仅记录比较选项卡中不匹配的数组(i,j)坐标 . 您应该修改它以记录您需要的任何其他信息:
EDIT:
在回复您的评论时,此版本将使用TRUE和FALSE填充比较表: