Excel的VBA问题

来源:百度知道 编辑:UC知道 时间:2024/06/08 15:58:44
A B C D
1 2 3 4
3 4
5 6
....
....
要求用VBA编程的方法从A B中知道A=C B=D的行
不是同行 要一句过的 例如if 。。。。。。。。。。。。 then cells(1,5)=1
省略号就是代表上面的要求 下面的 都不行呀

Private Sub CommandButton1_Click()
For i = 1 To 3
If Range("A" & i).Value = Range("C1").Value And Range("B" & i).Value = Range("D1").Value Then
Range("E1").Value = i
End If
Next i
End Sub
如下VBA程序仅用一句语句,在E1单元格统计出A B中A=C B=D的行的总数:
Private Sub CommandButton2_Click()
Range("E1").FormulaArray = "=SUM(IF(($A$1:$A$65535=$C$1)*($B$1:$B$65535=$D$1),1,0))"
End Sub

你是同行比较 A=C B=D?

还是A B分别都与C1 D1比较?

而且你这一句过不了.没有循环无法处理

if cells(i,1).value != "" then cells(1,5)=1