Consulting

Results 1 to 5 of 5

Thread: FINDING LAST ROW IN COLUMN NOT WORKING

  1. #1
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location

    FINDING LAST ROW IN COLUMN NOT WORKING

    I am trying to find the last row with data in a single column. The result should show row 59, however it shows row 1. I have one blank row in my column, which is row 2.

    My code:
    Sub LastRow1()
    Dim sht1 As Worksheet
    Dim Lr1 As Long
    Dim rng1 As Range
    
    Set sht1 = Worksheets("Contents")
    
    With sht1
    Lr1 = Cells(Rows.Count, "C").End(xlUp).Row
    
    MsgBox Lr1
    
    Set rng1 = sht1.Range("C3:C" & Lr1)
    End With
    End sub
    The message box answer = 1.

    I can't see what is wrong?

  2. #2
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Hi Dean
    Try this
    Lr1 = .Range("C" & Rows.Count).End(xlUp).Row

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    Ride the wind to the sun
    Posts
    2,593
    Sub LastRow1()
        Dim rng1 As Range
        
        With Worksheets("Contents")
            Set rng1 = .Range("C3:C" & .Cells(.Rows.Count, 3).End(xlup).Row)
        End With
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Regular
    Joined
    Jan 2018
    Posts
    49
    Location
    You need to add a dot before Cells property.
    Lr1 = .Cells(Rows.Count, "C").End(xlUp).Row

  5. #5
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location
    Thank you all!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •