+ Reply to Thread
Results 1 to 6 of 6

macro or VBA to count the range cells

  1. #1
    Registered User
    Join Date
    07-16-2014
    Location
    new york
    MS-Off Ver
    2013
    Posts
    6

    macro or VBA to count the range cells

    hi
    i'm working on a file that it has almost 3600 pages.
    now, I have copies all data into excel and need a quick calaluation but it is too much cells to count. so i'm looking for help with the VBA code that would count the cells with the range.

    see an example (I made a short example) attach file.

    on column A
    it begins with
    Tree
    st1
    the range (from cell A3-A13)
    it should COUNT it has 11 trees (cells)

    then, it would repeat
    tree
    st2
    the range (from cell A16-A20)
    it should COUNT IT HAS 5 tress (cells)
    see the short summary

    so, what I'm looking for is a formula or VBAthe code that could count the range between each tree as the data is not constant as the number of tress are vary for each street.

    thanks in advance for the help.
    Attached Files Attached Files
    Last edited by chaumay809; 04-26-2015 at 11:21 AM. Reason: change of the title

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: macro or VBA to count the range cells

    There is a formula you can use,
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    You will have to type end at the very last cell though.

    end.jpg

    Then the formulas can find the row numbers.

    4-26-2015 10-26-21 AM.jpg

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: macro or VBA to count the range cells

    1) Insert a blank row at the top

    2) Insert a blank column A where we will add an indexing column of numbers.

    3) Add the one more Tree a the bottom of the data, then directly below that put the word End for the street name.
    http://screencast.com/t/4MY8MCt1Aeo0

    4) In A2 enter this formula and copy down all the way :
    =IF(OR(B2="Tree",B2= ""), INT(A1)+1, A1+ 0.001)

    5) To pull out the street names, put this starting formula in D4 and copy down until street names stop appearing:
    =INDEX($B:$B, MATCH(ROW(A1),$A:$A, 0)+1)

    6) To pull out the Totals, put this starting formula in F4 and copy down:
    =IF(OR(D4="End", D4=""), "", MOD(INDEX(A:A, MATCH(ROW(A1)+0.9999999,A:A, 1)),1)*1000-1)
    http://screencast.com/t/ZQq21CdHoJ
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    07-16-2014
    Location
    new york
    MS-Off Ver
    2013
    Posts
    6

    Re: macro or VBA to count the range cells

    on the file, column 3 is blank, empty.
    I put there is to show what the result it should be.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: macro or VBA to count the range cells

    Attached is my suggested solution, for reference.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    07-16-2014
    Location
    new york
    MS-Off Ver
    2013
    Posts
    6

    [SOLVED] Re: macro or VBA to count the range cells

    it solved part of my problem.
    thanks.

+ 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. Count cells in a range that match a specific criteria in a different cell range
    By RhapsodyBay in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-13-2015, 02:10 PM
  2. Count a Range of cells if another range of cells meets criteria
    By mjg060468 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-21-2013, 02:57 PM
  3. [SOLVED] Count in a range, where identical adjacent cells count as one instance.
    By the-algebraist in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-05-2013, 11:18 AM
  4. Replies: 6
    Last Post: 11-11-2012, 12:40 AM
  5. [SOLVED] Count a range of cells if another range meets criteria
    By LadySetsuka in forum Excel General
    Replies: 8
    Last Post: 04-14-2012, 10:09 AM

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