0

我需要在我的 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"

很明显我在这里做错了什么。

4

1 回答 1

2

你可能的意思是:

If BrokerCell <> "" And Range("$Q$5").Value > 0

您正在将文字字符串“$Q$5”与文字字符串“0”进行比较。

于 2013-10-07T19:21:45.073 回答