当 $A$5 的值等于“公司 2”时,我需要这个宏来隐藏某些列。下面的查询成功隐藏了列,但没有执行打印循环。设置它的正确方法是什么?
Sub PrintAll()
Dim BrokerCell As Range
Dim TotalCell 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 = "Company 2" Then
Set Rng = ThisWorkbook.Names("Company2").RefersToRange
Else: Set Rng = ThisWorkbook.Names("Company3").RefersToRange
End If
If Range("$A$5").Value = "Company 2" Then
Columns("M:O").Select
Selection.EntireColumn.Hidden = True
Else: Columns("M:O").Select
Selection.EntireColumn.Hidden = False
For Each BrokerCell In Rng
If BrokerCell <> "" And Range("$S$5").Value <> "" Then
Wks.Range("$B$5").Value = BrokerCell.Text
Wks.PrintOut
End If
Next BrokerCell
End If
End Sub