+ Reply to Thread
Results 1 to 11 of 11

Finding the last non blank cell in a row

  1. #1
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329

    Finding the last non blank cell in a row

    Hello.

    I need a cell function that tells me on which cell the last non blank cell is at.

    I have 300 rows with numbers in column A. Row 301 - 310 are blanks and than there are some rows with numbers from 311 to X.

    How do I find the last row in column A that are not blank? I want it to be dynamic.


    /Anders

  2. #2
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    Do you mean its value or is address ?

    Carim

  3. #3
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329
    Its adress.

    /Anders

  4. #4
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by a94andwi
    Hello.

    I need a cell function that tells me on which cell the last non blank cell is at.

    I have 300 rows with numbers in column A. Row 301 - 310 are blanks and than there are some rows with numbers from 311 to X.

    How do I find the last row in column A that are not blank? I want it to be dynamic.


    /Anders
    =309+COUNTA(A310:A65536)

    should find it

    ---
    Si fractum non sit, noli id reficere.

  5. #5
    Registered User
    Join Date
    05-30-2006
    Posts
    33

    Done for u!!

    Hi,
    You can use the below code and get the desired result.
    Create a ne module and write this VBA code.The message will the displayed aswell as it will select the last blank cell.


    Sub find_out_lastblankcell()
    Sheets("sheet1").Select
    x = Range("A65536").End(xlUp).Row
    For i = x To 1 Step -1
    If Cells(i, 1) = "" Then
    MsgBox "row" & i & " column " & 1
    Cells(i, 1).Select
    Exit For
    End If
    Next i
    End Sub


    Regards,
    Roshin.P.P

  6. #6
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329
    Hello.

    It is not really that kind of calulation I need.
    If I select cell B3 and I want to know which row in Column A that has the last value. The values in Column A are dynamic and changes each day so I can not use any hard coded function.

    /Anders

  7. #7
    Registered User
    Join Date
    05-30-2006
    Posts
    33

    Done for u!!

    hi please ignore my above code.That will take you to the last blank cell.For last non blank cell use this code.(Selection will go there)

    Sub find_out_lastnonblankcell()
    Sheets("sheet1").Select
    x = Range("A65536").End(xlUp).Row
    Cells(x, 1).Select
    End Sub

    Regards,
    Roshin.P.P

  8. #8
    Registered User
    Join Date
    05-30-2006
    Posts
    33

    100% dynamic

    This VBA code is 100% dynamic.Just run the macro everytime u change the data.

    cheeers!!
    Roshin

  9. #9
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329
    Quote Originally Posted by roshinpp_77
    Hi,
    You can use the below code and get the desired result.
    Create a ne module and write this VBA code.The message will the displayed aswell as it will select the last blank cell.


    Sub find_out_lastblankcell()
    Sheets("sheet1").Select
    x = Range("A65536").End(xlUp).Row
    For i = x To 1 Step -1
    If Cells(i, 1) = "" Then
    MsgBox "row" & i & " column " & 1
    Cells(i, 1).Select
    Exit For
    End If
    Next i
    End Sub


    Regards,
    Roshin.P.P
    This is a useful function. If I would like to have a variable in the function:
    "Sub find_out_lastblankcell(startcell)" to create a range.

    I would also like to add that the function always chooses the active sheet instead of a hardcoded one. How can I change "Sheets("sheet1").Select" to a more dynamic version?

    /Anders
    Last edited by a94andwi; 11-07-2006 at 08:18 AM.

  10. #10
    Registered User
    Join Date
    05-30-2006
    Posts
    33

    Check now!!

    Hi
    This code will select from the active sheet.
    Also you can change the column A to any column .The character marked in red has to be changed

    Sub find_out_lastnonblankcell()
    ActiveSheet.Select
    x = Range("A65536").End(xlUp).Row
    Cells(x, 1).Select
    End Sub


    Regards,
    Roshin

  11. #11
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    Please Login or Register  to view this content.
    HTH
    Carim

+ 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