I need to be able to deterimine that last row in a worksheet that contains data. The number of columns is fixed but the rows will vary. Once I have the number or rows, I can set the "Printarea" property correctly which is what I need to do. I'm sure this is an easy one but it is escaping me. Any help would be greatly appreciated. Thanks.
There are various methods of finding the last row of data.
One of them is the following:
See the attached file.Code:Dim LastRow As Long LastRow = ActiveSheet.Range("A65536").End(xlUp).Row
The code behind the command button is:
Code:Private Sub CommandButton1_Click() Dim LastRow As Long Dim ws As Worksheet Set ws = ActiveSheet LastRow = ws.Range("A65536").End(xlUp).Row With ws.PageSetup .PrintArea = "A1:E" & LastRow End With End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)