R
RJR
I have this code in a file that searches an entire form and is activated to
print preview a file. When it works, it stops printing row at the last entry
in the sheet. I get the Compile error, Variable not defined when I fire the
macro and it appears at the "For Each "cell" .............
I need it to count rows with data in the first column and then when it comes
to the end, to send the document to the printer with only the rows with data
showing.. Any help would be appreciated.
Thanks
Sub findlastrow()
Dim lastrow As Long
Dim r As Range
lastrow = 1
For Each cell In Range(Cells(1, "A"), Cells(Rows.Count, "A").End(xlUp))
If Trim(cell.Text) <> "" Then
lastrow = cell.Row
End If
Next
Set r = ActiveSheet.Range("A1:M" & lastrow)
r.PrintPreview
' or
'Activesheet.PageSetup.PrintArea = r.address(external:=true)
'Activesheet.Printout
End Sub
print preview a file. When it works, it stops printing row at the last entry
in the sheet. I get the Compile error, Variable not defined when I fire the
macro and it appears at the "For Each "cell" .............
I need it to count rows with data in the first column and then when it comes
to the end, to send the document to the printer with only the rows with data
showing.. Any help would be appreciated.
Thanks
Sub findlastrow()
Dim lastrow As Long
Dim r As Range
lastrow = 1
For Each cell In Range(Cells(1, "A"), Cells(Rows.Count, "A").End(xlUp))
If Trim(cell.Text) <> "" Then
lastrow = cell.Row
End If
Next
Set r = ActiveSheet.Range("A1:M" & lastrow)
r.PrintPreview
' or
'Activesheet.PageSetup.PrintArea = r.address(external:=true)
'Activesheet.Printout
End Sub