[英]excel vba if cell contains value print area in excel spreadsheet?
I am trying to use vba code to print an area of excel (AC120:AT128) when a cell value contains "X" At the moment my code prints out the whole spread sheet but I only want it to print out the selected cell area. 我正在尝试使用vba代码在单元格值包含“ X”时打印excel区域(AC120:AT128)。此刻,我的代码打印出了整个电子表格,但我只希望它打印出所选单元格区域。
Can someone please show me how I can achieve this? 有人可以告诉我如何实现吗? thanks in advance. 提前致谢。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim celltxt As String
celltxt = ActiveSheet.Range("AQ98").Text
If InStr(1, celltxt, "X") Then
Dim ws As Worksheet
For Each ws In Worksheets
If ws.Range("AQ98") = "X" Then
ws.PrintOut
End If
Next ws
Else
End If
End Sub
I'm not sure what version of Excel you're using, but in Office 2010, you can simply use. 我不确定您使用的是哪个版本的Excel,但是在Office 2010中,您可以轻松使用。
Range("AC120:AT128").PrintOut()
Or 要么
Selection.PrintOut()
You can also use the set print area function, eg 您还可以使用设置打印区域功能,例如
ws.PageSetup.PrintArea = "AC120:AT128"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.