我这是自动找到最后一行的,符合你的要求,请试试。
Private Sub CommandButton1_Click()
Dim row_last As Integer
Dim temp1 As Integer
Selection.SpecialCells(xlCellTypeLastCell).Select
flag = False
Do While flag = False
If ActiveCell.Row = 1 Then
Exit Do
End If
Selection.End(xlToLeft).Select
temp1 = IsEmpty(ActiveCell.Value)
Selection.End(xlToRight).Select
temp2 = IsEmpty(ActiveCell.Value)
If temp1 = True And temp2 = True Then
Selection.Offset(-1, 0).Select
Else
flag = True
Exit Do
End If
Loop
Selection.End(xlToLeft).Select
row_last = ActiveCell.Row
Range(Cells(1, 1), Cells(row_last, 1)).Select
Selection.PrintOut Copies:=1
End Sub
Range("A1:A22").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
将以上代码粘贴至控件代码区。
可以实现自定义区域的打印 没问题