帮帮我们..
我需要一些代码在命令按钮来检查2个不同的列是否有相同的值..如果相同它会显示一个弹出消息..如果它不相同,它将显示一个弹出消息..
答案 0 :(得分:1)
从开发人员选项卡插入ActiveX控件命令按钮。然后单击查看代码。在标题和End Sub之间执行以下操作:
Dim totalRows As Long
Dim row As Long
totalRows = ActiveSheet.UsedRange.Rows.Count 'this assumes your used range is the two columns height.
For row = 1 To totalRows
If Cells(row, column1) = Cells(row, column2) Then
MsgBox "row" & row & "has the same values"
Else
MsgBox "row" & row & "does not have the same values"
End If
Next row
显然,column1和column2应该是列的实际索引。