Announcement

Collapse
No announcement yet.

Unconfigured Ad Widget

Collapse

Determining Number of Rows in Worksheet

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Determining Number of Rows in Worksheet

    Hi,

    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.

  • #2
    Re: Determining Number of Rows in Worksheet

    There are various methods of finding the last row of data.

    One of them is the following:
    Code:
    Dim LastRow As Long
    
    LastRow = ActiveSheet.Range("A65536").End(xlUp).Row
    See the attached file.

    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
    Attached Files
    Boo!

    Comment

    Trending

    Collapse

    There are no results that meet this criteria.

    Working...
    X