+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    117

    Count number of cells between two cells in same column

    Hello, First I apologize for asking a question that I KNOW has been asked before, I can't find it. All I need is a way to count how many cells are between two different cells that the user selects.I have all the selection,and userform programing done but this worksheetfunction.countif is not working for me, and it would be alot easier than some whole looping program just to add up how many cells there are between them.
    here is what i have so far
    Code:
    numberoflables = WorksheetFunction.CountIF(Topaddress & ":" & Bottomaddress, "?*")
    I get the "Topaddress" and "Bottomaddress" values with
    Code:
    Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    Label_Generater.TextBox1.ControlSource = ActiveWindow.ActiveCell.Address
    Topaddress = Label_Generater.TextBox1.ControlSource
    End Sub
    Sorry if I sound frustrated, I am...
    Thank you very much for your time,
    Last edited by TheNewGuy; 03-12-2010 at 09:07 AM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    3,714

    Re: Count number of cells between two cells in same column

    Just use COUNT.

  3. #3
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    117

    Re: Count number of cells between two cells in same column

    Do you mean simply change CountIF to Count?
    Code:
    numberoflables = WorksheetFunction.Count(Topaddress & ":" & Bottomaddress, "?*")
    Because I tried that and it gives me 0...
    Thanks

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    3,714

    Re: Count number of cells between two cells in same column

    My mistake. COUNT doesn't do what I thought it did. You could try adding blanks and non-blanks (COUNTA + COUNTBLANK)?

  5. #5
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    117

    Re: Count number of cells between two cells in same column

    I Figured it out, I had to create a custom Range. Like this
    Code:
    Dim MyRNG As Range
    Set MyRNG = Sheets("CONFIG").Range(Topaddress & ":" & Bottomaddress)
    
    numberoflables = WorksheetFunction.CountIf(MyRNG, "?*")
    This seems to work the way I need it to. I knew I was forgetting something easy Thanks for all your help.

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.2.0