Sub CompareAndCopy()
Dim wb As Workbook
Dim ws As Worksheet
Dim cell1 As Range, cell2 As Range, targetCell As Range
Set wb = ActiveWorkbook '将变量wb设置为活动工作簿
For Each ws In wb.Worksheets '对于工作簿中的每个工作表
Set cell1 = ws.Range("A1") '将变量cell1设置为第一个单元格
Set cell2 = ws.Range("B1") '将变量cell2设置为第二个单元格
Set targetCell = ws.Range("C1") '将变量targetCell设置为目标单元格
If cell1.Value = cell2.Value Then '如果cell1和cell2的值相等
targetCell.Value = cell1.Value '将目标单元格的值设置为cell1的值
End If
Next ws '继续下一个工作表
End Sub