我需要在我的 vba 中创建一个 IF AND THEN 语句。我在下面尝试了这段代码,虽然我没有收到任何错误,但它不起作用(即:当我运行宏时没有任何反应):
Sub PrintAll()
Dim BrokerCell As Range
Dim Rng As Range
Dim Wks As Worksheet
Set Wks = Worksheets("PRINT PAGE")
If Range("$A$5").Value = "Company 1" Then
Set Rng = ThisWorkbook.Names("Company1").RefersToRange
ElseIf Range("$A$5").Value = "Company2" Then
Set Rng = ThisWorkbook.Names("Company2").RefersToRange
Else: Set Rng = ThisWorkbook.Names("Company3").RefersToRange
End If
For Each BrokerCell In Rng
If BrokerCell <> "" AND "$Q$5" > "0" Then
Wks.Range("$B$5").Value = BrokerCell.Text
Wks.PrintOut
End If
Next BrokerCell
End Sub
宏在没有
AND "$Q$5" > "0"
很明显我在这里做错了什么。