Consulting

Results 1 to 3 of 3

Thread: Finding last cell in a column

  1. #1

    Question Finding last cell in a column

    Hi friends I am going to write a Function in VBA that I should have first cell and last cell in a column. the first is easy but I don't know how I can do it for the last cell.
    I don't know what should I write instead of x in the lastCell.
    I hope you can help me

    firstCell = Cells(1, 1)
    lastCell = Cells(x, 1)

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    Something like:
    Sub test()    
        Dim FirstCell As Range
        Dim LastCell As Range
        
        Set FirstCell = Cells(1, 1)
        Set LastCell = Cells(Rows.Count, 1).End(xlUp)
        
        Range(FirstCell, LastCell).Select
    End Sub
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Sub M_snb()
      sn = sheet1.cells(1).currentregion
      msgbox sheet1.cells(ubound(sn),1)
    End Sub

Posting Permissions

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