+ Reply to Thread
Results 1 to 7 of 7

Find first and last non-blank (non-empty) cell, and First blank cell in a row or column

  1. #1
    Registered User
    Join Date
    11-16-2015
    Location
    London
    MS-Off Ver
    2013
    Posts
    51

    Find first and last non-blank (non-empty) cell, and First blank cell in a row or column

    I saw and tried different methods to find number of row or column, for First and Last non-blank (non-empty) cell in a row or column, and First blank cell in a row or column.

    Codes that include .End(xlUp) or similar to it, for the case that for example, A3:A10 is a defined table, but A3 is empty from the top and A10 is empty from the bottom, it does not answer and does not check cells A3 and A10.

    I also found the following function:

    Please Login or Register  to view this content.
    and use that in my code as

    iRow4 = vba_last_row(ThisWorkbook.Sheets("DATA"), "O")
    which gives:

    Please Login or Register  to view this content.
    What's the solution?
    Last edited by niksirat2030; 08-31-2022 at 05:58 AM.

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,224

    Re: Find first and last non-blank (non-empty) cell, and First blank cell in a row or colum

    Please Login or Register  to view this content.
    Artik

  3. #3
    Registered User
    Join Date
    11-16-2015
    Location
    London
    MS-Off Ver
    2013
    Posts
    51

    Re: Find first and last non-blank (non-empty) cell, and First blank cell in a row or colum

    Quote Originally Posted by Artik View Post
    Please Login or Register  to view this content.
    Artik
    I try
    Please Login or Register  to view this content.
    1- error 13: try mismatch
    2- run-time error 1004: Method 'Range' of object '_Worksheet' failed.
    3- not error , but wrong answer, for my data:

    Attachment 794177

  4. #4
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: Find first and last non-blank (non-empty) cell, and First blank cell in a row or colum

    Perhaps the below will help:
    Please Login or Register  to view this content.
    Last edited by CheeseSandwich; 08-31-2022 at 03:10 AM. Reason: Updated to deal with a full table
    If things don't change they stay the same

  5. #5
    Registered User
    Join Date
    11-16-2015
    Location
    London
    MS-Off Ver
    2013
    Posts
    51

    Re: Find first and last non-blank (non-empty) cell, and First blank cell in a row or colum

    Quote Originally Posted by CheeseSandwich View Post
    Perhaps the below will help:
    Please Login or Register  to view this content.
    Can use this code as a Function like vba_last_row to use that any place of my code , for example

    iRow4 = vba_last_row(ThisWorkbook.Sheets("DATA"), "O") for find last nonempty cell in column O

    or

    iRow4 = vba_last_row(ThisWorkbook.Sheets("DATA"), "A") for find last nonempty cell in column A?

    without depend on a certain predefined Table in any sheet.

    If yes, how can do that?

  6. #6
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: Find first and last non-blank (non-empty) cell, and First blank cell in a row or colum

    Are you working with tables or just ranges of data?

    I ask as (xlup) will return the bottom of a table even if the range within the table is empty. This is why i have referenced the table column to then find the last used cell within that column. If you reference the entire column where the table resides then it will only find the bottom of the table and not the last used row within the table.

    How many tables do you have on each sheet?
    What column in each table are you using to identify the last/ first cell?

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Find first and last non-blank (non-empty) cell, and First blank cell in a row or colum

    niksirat2030 ,

    Find method raise the runtime error when no cell found, I mean no data in the search range.
    So, Change to
    Please Login or Register  to view this content.
    Now you can use it like
    Please Login or Register  to view this content.
    When no data, the function returs 0.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Ignore blank cells if cell in column C is empty
    By Chris220 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2019, 06:08 AM
  2. [SOLVED] Find non blank cell in a column (range Specified) and insert formula to other cell in same
    By jpbisani in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-18-2018, 06:11 AM
  3. [SOLVED] select last blank cell instead of last empty cell in a column
    By alexcrofut in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-11-2014, 01:50 PM
  4. [SOLVED] Find first non-blank cell after a group of blanks copy offset cells, find next blank, loop
    By gwsampso in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-21-2012, 06:11 AM
  5. Find first blank cell in column if rightmost cell is non blank
    By Mothman in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-19-2010, 02:22 AM
  6. color blank cell red if blank or empty and count its occurances
    By stoey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2009, 08:21 AM
  7. Find empty/null/blank cell in a conditional format
    By Dabooj in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-09-2008, 10:50 AM

Tags for this Thread

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