+ Reply to Thread
Results 1 to 8 of 8

Function to count rows in column A

  1. #1
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Function to count rows in column A

    Hi,

    In the code I am writing, I am often having to count the number of used rows in column A (there are no blanks). I'd therefore like a function to automate this. Something along the lines of :-

    Please Login or Register  to view this content.
    How would I code the function, and then refer to it in the code?

    Thanks in advance
    Last edited by bd528; 09-11-2010 at 02:45 PM.

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

    Re: Function to count rows in column A

    The most common way is probably to use...

    This example look down column A and finds the end row and returns it as a number and then is used as a variable in the For Next loop

    Please Login or Register  to view this content.
    Here is a reference but there are many others...

    http://www.xldynamic.com/source/xld.LastValue.html#vba

  3. #3
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Function to count rows in column A

    If you have no blanks within range A:A then

    Please Login or Register  to view this content.
    This will return last non-empty row number.

    U can also use CountA function to determine amount of non-empty cells which will be equal last non-empty cell row number.

    Please Login or Register  to view this content.
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  4. #4
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Function to count rows in column A

    @jeffreybrown

    FYI. To delete blank rows you can actually first select all blank cells within a range then delete them

    Please Login or Register  to view this content.
    Or

    Please Login or Register  to view this content.
    IMO this much easier and faster than looping through all blanks cells.
    Last edited by contaminated; 09-11-2010 at 01:46 PM.

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

    Re: Function to count rows in column A

    Vusal,

    Thanks for the help...

    Must admit still trying to learn all the different ways...

  6. #6
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Function to count rows in column A

    Thanks for the feedback - I will go with the following option :-

    Quote Originally Posted by contaminated View Post

    Please Login or Register  to view this content.
    If anyone has the time though, could someone still explain how to do this via custom function, refering the sheet's name. I'd like to be able to understand how to send the sheets name to the function and then work on that sheet

    Thanks

  7. #7
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Function to count rows in column A

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Function to count rows in column A

    Quote Originally Posted by contaminated View Post
    Please Login or Register  to view this content.
    Exactly what I needed. Thank you.

+ 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