+ Reply to Thread
Results 1 to 6 of 6

IF Statement that Counts

  1. #1
    Registered User
    Join Date
    05-31-2017
    Location
    United States
    MS-Off Ver
    Microsoft Office 2016
    Posts
    9

    IF Statement that Counts

    I am trying to accomplish the following. I have a list of data that contains headers and some unique fields. See the attachment for the example.

    In short, I need the KEY column to count, starting from 1, however, on rows that have a matching Document Number, it uses the same KEY value and then continues on counting where it left off.

    I am trying to figure out the best way to do this and while I could make a super long IF statement, I feel like there is a better way.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: IF Statement that Counts

    Right Click on your sheet name at the bottom of excel and select view code

    Paste this code into the module that open and close it.

    Then Type a number in column B

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    05-31-2017
    Location
    United States
    MS-Off Ver
    Microsoft Office 2016
    Posts
    9

    Re: IF Statement that Counts

    Hi mehmetcik,

    This is nearly exactly what I was looking for. I appreciate the time taken for this.

    It works in my uploaded test Excel file, but not so much in actual practice with the real document. There are a few headers that I left out in the example document, because (so I thought) they aren't applicable to the example. In the live document that I am using, DOCNMBR will be column G (7). Therefore, should I adjust

    Please Login or Register  to view this content.
    To look like this below?

    Please Login or Register  to view this content.
    Another comment to make is the live document I am using uses formulas everywhere. Meaning, DOCNMBR isn't a plain text of '123456' and its =IF($H2<>"",'Pay Entry'!B14,""). Would this code provided still function even if the cells are formulas?

    If desired, I can upload a more accurate copy of my live/real Excel file. I figured a formula was going to be provided, not code, hence the reason for not uploading the full document.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: IF Statement that Counts

    Make the change you suggest. It should work.

  5. #5
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: IF Statement that Counts

    A formula method..

    enter the first number by hand in L2..
    So L2 = 1

    IN L3 and filled down
    =IF(COUNTIF(K$2:K3,K3)>1,VLOOKUP(K3,K$2:L3,2,0),MAX(L$2:L2)+1)

  6. #6
    Registered User
    Join Date
    05-31-2017
    Location
    United States
    MS-Off Ver
    Microsoft Office 2016
    Posts
    9

    Re: IF Statement that Counts

    Worked like a charm in both cases! Thank you!

+ 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. Subtotal Formula that counts if statement is true
    By shelton_4 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-15-2013, 10:57 PM
  2. Replies: 2
    Last Post: 05-08-2013, 04:56 PM
  3. [SOLVED] Counts
    By shootingstarz in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-25-2012, 04:39 PM
  4. Logical statement plus counts.
    By Renildrah in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-02-2012, 03:31 AM
  5. Excel 2007 : Need help with Counts
    By mrtommy03 in forum Excel General
    Replies: 1
    Last Post: 08-29-2011, 01:49 PM
  6. Sum of two counts
    By scottnshelly in forum Excel General
    Replies: 7
    Last Post: 12-22-2010, 02:12 PM
  7. Counts
    By darkhat01 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-07-2008, 02:33 PM
  8. Counts more than one
    By dTHMTLGOD in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-25-2006, 09:00 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