0

$A$5 の値が "Company 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
4

2 に答える 2