+ Reply to Thread
Results 1 to 8 of 8

count filled and empty rows till the last filled row

  1. #1
    Registered User
    Join Date
    08-20-2011
    Location
    qatar
    MS-Off Ver
    Excel 2007
    Posts
    9

    Thumbs up count filled and empty rows till the last filled row

    Hi all

    I need help to edit a macro or to write a udf to do the follows:


    i have a workbook with many sheets
    in each sheet there is diffrent number of rows


    I need :

    1- a function to count all the rows in a sheet ( filled and blank rows in between the filled ones ) from the first row in the sheet to the last row filled with data .

    I need this function to be able to insert a statement at the end of each sheet after the last row in each sheet

    and because each sheet has a diffrent number of rows(either the blank rows or the filled ones ) i could not did this

    I tried to use CountA ,CountBlank ,UsedRange property ,Range.Rows.count property
    but bacause of the diffrentiation of each sheet this did not help

    I am not professional in vba so maybe i did not use the right combination of these functions

    so I guess that the right combination of these function will work
    or maybe u can suggest better solution



    Thaxxxxxxx in advance
    i really appreciate your help

    there is an example worksheet in the attachments
    Attached Files Attached Files
    Last edited by Dalal; 08-29-2011 at 04:41 AM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,662

    Re: count filled and empty rows till the last filled row

    Please Login or Register  to view this content.
    Ben Van Johnson

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

    Re: count filled and empty rows till the last filled row

    Hi Dalai,

    See if the formulas in the attached work for you. They use an Indirect and Row() function to get the answer I think you want.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: count filled and empty rows till the last filled row

    Hello Dalal,

    Here is the preffered method of finding the "true" last row. This is not influenced by the Excel's habit of "tracking" what you have done like formulas and the Range End method are.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

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

    Re: count filled and empty rows till the last filled row

    Hi Leith,

    I'm not as good with the Cells.Find method, so I'm trying to learn.

    Your code of
    Please Login or Register  to view this content.
    seems to return the last value and not the number of rows.

    What am I missing, as I know you are rarely wrong.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: count filled and empty rows till the last filled row

    Hello Marvin,

    You are correct that the Cells.Find method returns the last entry in the last row. You will notice in the example that I define the variable LastRow as a Variant.This allows it to be set to the cell that contains the last entry. Next, LastRow is checked to see it is was set to cell value. If the worksheet is blank then LastRow equals the special object value Nothing and the default row is set to 1. Once the checks are made, LastRow is then assigned the row value. Using a variant allows the variable to go from a Range object to Long integer representing the row.

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

    Re: count filled and empty rows till the last filled row

    Thanks - I needed to see how you did that.

  8. #8
    Registered User
    Join Date
    08-20-2011
    Location
    qatar
    MS-Off Ver
    Excel 2007
    Posts
    9

    Thumbs up Re: count filled and empty rows till the last filled row

    Hi

    Thxxxxxxxxx...All ProtonLeah ...Leith ...MarvinP

    I tried all these solutions and they worked nicely


    I,m learning nice new ideas from u all

+ 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