+ Reply to Thread
Results 1 to 5 of 5

COUNTIF with 2 Conditions met UNTIL 2 Condition met

Hybrid View

  1. #1
    Registered User
    Join Date
    07-26-2012
    Location
    US Military/Germany
    MS-Off Ver
    Excel 2010
    Posts
    12

    COUNTIF with 2 Conditions met UNTIL 2 Condition met

    Hello, this is my first post to the forum. Thank you in advance for any help you can give me.

    I'm coding with VBA

    Tables and Formula provided are for reference only.

    What I need is to count the Cells in Column C that are greater than 1 For Items PName and ANAME(X,Y,Z).
    My problem is that my number of rows for each ANAME(X,Y,Z) will vary and are NOT always in the same range/cell reference.
    (e.g ANAMEX may be in spot where ANAMEZ is and vise-versa).

    Something like COUNTIF/UNTIL code. Maybe?

    The folowing EXAMPLE works IF my references were constant, but they are not.

    Formula: copy to clipboard
    =IF(A1="PName",IF(ISERROR(FIND(B1,"X",1))=TRUE,COUNTIF(C3:C7,">1"),""),"")


    Column A
    Column B
    Column C
    PName
    ANAMEX
    #'s
    Text
    10
    #'s
    Text
    10
    #'s
    Text
    10
    #'s
    Text
    10
    #'s
    Text
    10
    PName
    ANAMEY
    #'s
    Text
    10
    #'s
    Text
    10
    #'s
    Text
    10
    #'s
    Text
    10
    #'s
    Text
    10
    PName
    ANAMEZ
    #'s
    Text
    10
    #'s
    Text
    10
    #'s
    Text
    10
    #'s
    Text
    10
    #'s
    Text
    10

    Totals Area

    Column E
    Column F
    Row 2
    X
    Should Count to 5
    Row 3
    Y
    Should Count to 5
    Row 4
    Z
    Should Count to 5

    I hope I explained myself properly. Thank you.
    Last edited by DnDXan; 07-29-2012 at 02:21 PM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: COUNTIF with 2 Conditions met UNTIL 2 Condition met

    before i offer any other suggestions/help on this, take a look at the countifS() function (note the S). this may give you what you need, as it allows counting based on multiple criteria
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    07-26-2012
    Location
    US Military/Germany
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: COUNTIF with 2 Conditions met UNTIL 2 Condition met

    Quote Originally Posted by FDibbins View Post
    before i offer any other suggestions/help on this, take a look at the countifS() function (note the S). this may give you what you need, as it allows counting based on multiple criteria
    I have tried COUNTIFS, however it does not work the way i need it too because my cell references are not constant. Thank You.

    ---------- Post added 07-27-2012 at 12:00 AM ---------- Previous post was 07-26-2012 at 11:59 PM ----------

    rylo, I will give this a try and let you know. Thank You.

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: COUNTIF with 2 Conditions met UNTIL 2 Condition met

    Hi

    Clunky, but should get you there
    Sub aaa()
      For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
        If Cells(i, 1) = "PName" Then
          If Len(itemm) = 1 Then
            outrow = Cells(Rows.Count, "E").End(xlUp).Offset(1, 0).Row
            Cells(outrow, "E").Value = itemm
            Cells(outrow, "F").Value = cntr
          End If
          
          itemm = Right(Cells(i, 2), 1)
          cntr = 0
        End If
        If Cells(i, 3) > 1 Then cntr = cntr + 1
      Next i
      If Len(itemm) = 1 Then
        outrow = Cells(Rows.Count, "E").End(xlUp).Offset(1, 0).Row
        Cells(outrow, "E").Value = itemm
        Cells(outrow, "F").Value = cntr
      End If
    End Sub
    rylo

  5. #5
    Registered User
    Join Date
    07-26-2012
    Location
    US Military/Germany
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: COUNTIF with 2 Conditions met UNTIL 2 Condition met

    Worked great. Thank you very much.

+ 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