+ Reply to Thread
Results 1 to 25 of 25

Find last cell in a spreadshhet using VBA

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Find last cell in a spreadshhet using VBA

    Here you go.
    it will select the last row with data and not a formula.
    Please mark the thread as SOLVED if it is

    Sub FindLastData()
    
    Dim r, i As Integer
    r = Range("A:A").Cells.SpecialCells(xlCellTypeLastCell).Row
    
    For i = r To 1 Step -1
    
        If VBA.Left(Range("A" & i).Formula, 1) <> "=" Then
            Range("A" & i).Select
            Exit For
        End If
    Next
    
    End Sub

  2. #2
    Registered User
    Join Date
    07-13-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Find last cell in a spreadshhet using VBA

    Quote Originally Posted by Kelshaer View Post
    Here you go.
    it will select the last row with data and not a formula.
    Please mark the thread as SOLVED if it is

    Sub FindLastData()
    
    Dim r, i As Integer
    r = Range("A:A").Cells.SpecialCells(xlCellTypeLastCell).Row
    
    For i = r To 1 Step -1
    
        If VBA.Left(Range("A" & i).Formula, 1) <> "=" Then
            Range("A" & i).Select
            Exit For
        End If
    Next
    
    End Sub


    This selects cell A1 which contains the column labels which have been hand written and do not include a formula, sorry forgot to put column labels on the sample here is a new one
    Attached Files Attached Files

  3. #3
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Find last cell in a spreadshhet using VBA

    On your sample, this selects cell A458

    Sub findlast()
        Dim lr As Long
            For lr = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
                If Len(Range("A" & lr)) > 0 Then Exit For
            Next
        Application.Goto Range("A" & lr)
    End Sub
    HTH
    Regards, Jeff

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1