VBA条件打印
Private Sub CommandButton1_Click()Dim sText, sPrintArea
'1只要B40:D40单元格有文本就打印A35:Q62区域
sText = Trim(Range("B40").Value & Range("C40").Value & Range("D40").Value)
If sText <> "" Then
sPrintArea = "$A$35:$Q$62"
End If
'只要B75:D75单元格有文本就打印A70:Q97区域
sText = Trim(Range("B75").Value & Range("D75").Value & Range("D75").Value)
If sText <> "" Then
If sPrintArea = "" Then
sPrintArea = "$A$35:$Q$62"
Else
sPrintArea = "$A$35:$Q$62, $A$70:$Q$97"
End If
End If
'只要B105:D105单元格有文本就打印A100:Q127区域
sText = Trim(Range("B105").Value & Range("C105").Value & Range("D105").Value)
If sText <> "" Then
If sPrintArea = "" Then
sPrintArea = "$A$100:$Q$127"
Else
sPrintArea = sPrintArea & "," & "$A$100:$Q$127"
End If
End If
If sPrintArea <> "" Then
ActiveSheet.PageSetup.PrintArea = sPrintArea
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
End If
End Sub
求大神改成 图中A6数字是1 就打印B456789 ,C456789.是2就打印B456789 ,C456789 D456789,E456789,是3就打印B456789 ,C456789 D456789,E456789F456789,G456789S 4..........
A12就打印B10-B15,C10-C15 ,是2就打印B10-B15 ,C10-C15,D10-D15,E10-E15,是3就打印B10-B15 ,C10-C15,D10-D15,E10-E15,F10-F15,G10-G15 ,