+ Reply to Thread
Results 1 to 7 of 7

VB to find & positioning on first blank cell

Hybrid View

  1. #1
    Registered User
    Join Date
    09-29-2009
    Location
    Oporto
    MS-Off Ver
    Excel 2007
    Posts
    31

    VB to find & positioning on first blank cell

    Dear Sirs,

    I don't know almost anything about VB, but I need to manage a way of create a macro, to find and positioning the cursor in the first blank cell, down the column A, by analyzing all the columns from A to AK, and detect the last non blank cell in any of those.

    Could I count on your expertise?

    Beforehand thanks for the help.

    Carlos Maldonado
    Last edited by carlosmaldonado; 03-18-2011 at 07:58 AM. Reason: SOLVED

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: VB to find & positioning on first blank cell

    I think this is what you asked for. This will select the first blank cell in column A and will tell you what the last non blank cell in A is:

    Option Explicit
    
    Sub FirstEmptyandLastCell()
    Dim lastrow As Long, icell As Long
    Dim Msg As String
    
    lastrow = Range("A" & Rows.Count).End(xlUp).Row
    
    For icell = 1 To lastrow
        If Range("A" & icell).Value = "" Then
            Range("A" & icell).Select
            GoTo Finish
        End If
    Next icell
    
    Finish:
    Msg = MsgBox("The last range with a value is in cell A" & lastrow, vbOKOnly, "Last Cell")
    
    End Sub

  3. #3
    Registered User
    Join Date
    09-29-2009
    Location
    Oporto
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VB to find & positioning on first blank cell

    Hi stnkynts,

    first of all thanks. Your input tells me where the last cell in the A column is, but what I need, instead is to positioning the cursor over there, to start to fill the file w/o having to scroll down evrytime I want to get there. Is that possible?

    Thanks
    CM

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: VB to find & positioning on first blank cell

    There are many ways you can do this. Just to make sure i understand correctly you want to select the row after the last row with data in it. Something like this should work just fine:

    Sub selectlastrow()
    
    Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Select
    
    End Sub

  5. #5
    Registered User
    Join Date
    09-29-2009
    Location
    Oporto
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VB to find & positioning on first blank cell

    Hi stnkynts, anyway thanks for your help.

    Regards
    CM

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,261

    Re: VB to find & positioning on first blank cell

    Hi Carlos
    The VBA to find the last non blank in Col A only looks like:
    Sub SelectLastRow()
        Dim LastRow As Double
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row
        Cells(LastRow, "A").Select
    End Sub
    If you need to find the last in columns A to AK (AK = Column 37) then try:
    Sub SelectLastRow()
        Dim LastRow As Double
        Dim ColCtr As Double
        Dim MaxLastRow As Double
        MaxLastRow = 1
        
            For ColCtr = 1 To 37 ' Col AK = Col 37
            LastRow = Cells(Rows.Count, ColCtr).End(xlUp).Row
                If LastRow > MaxLastRow Then
                    MaxLastRow = LastRow
                End If
            Next ColCtr
        Cells(MaxLastRow, "A").Select
    End Sub
    You will need to add 1 to the last statement to get the first blank row as in:
    Cells(MaxLastRow + 1 , "A").Select
    Last edited by MarvinP; 03-17-2011 at 10:32 AM.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  7. #7
    Registered User
    Join Date
    09-29-2009
    Location
    Oporto
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VB to find & positioning on first blank cell

    Dear Marvin,

    you're a pro! You've interpreted correctly my problem and managed a 100 % useful solution! Brilliant!

    Many thanks

+ 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