+ Reply to Thread
Results 1 to 12 of 12

Count cells from left to right based on > value

  1. #1
    Registered User
    Join Date
    11-18-2015
    Location
    Dallas Texas
    MS-Off Ver
    MS Office 2016
    Posts
    11

    Count cells from left to right based on > value

    Hello Forum,

    Thank you in advance for your help.

    I'm looking for some help writing this formula or VBA script. I have a report consisting 10,000 records and for each line, I'm trying to calculate a consistent value count from left to right when the score is greater than a set number. IE: 94 in this example.

    I'm looking for a formula or script to count based on a number greater than 94 starting from cell A1, then to A2, and so on and stopping when the value is less than the 94.

    See below

    Example #1 Expected result = 3
    A1=96
    B1=98
    C1=100
    D1=79
    E1=99
    F1=97

    Example #2 Expected result = 2
    A1=96
    B1=98
    C1=27
    D1=99
    E1=99
    F1=97


    Thanks again for your help

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2407 Win 11 Home 64 Bit
    Posts
    24,084

    Re: Count cells from left to right based on > value

    Please explain your logic. How did you arrive at 3 and 2 as the expected results. What am I missing?
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    11-18-2015
    Location
    Dallas Texas
    MS-Off Ver
    MS Office 2016
    Posts
    11

    Re: Count cells from left to right based on > value

    Sorry, here ya go. In Example 1 the formula will look at cell A1 and if the value is > 94 it will count as 1 and proceed to next cell (B2). If B2 is greater than 94, it will count as 2, then looks at C1 and if greater than 94, will count as 3. When it hits cell D1 the value is less than 94 so it stops counting. Cells E1 and F1 are greater than 94, but we do not want to include. So basically it will count each value from left to right and will not stop until it hits a value that is greater than 94. Hope this help. Thank you so much

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2407 Win 11 Home 64 Bit
    Posts
    24,084

    Re: Count cells from left to right based on > value

    Here is a VBA solution

    Please Login or Register  to view this content.
    How to install your new code
    • Copy the Excel VBA code
    • Select the workbook in which you want to store the Excel VBA code
    • Press Alt+F11 to open the Visual Basic Editor
    • Choose Insert > Module
    • Edit > Paste the macro into the module that appeared
    • Close the VBEditor
    • Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)


    To run the Excel VBA code:
    • Press Alt-F8 to open the macro list
    • Select a macro in the list
    • Click the Run button

  5. #5
    Registered User
    Join Date
    11-18-2015
    Location
    Dallas Texas
    MS-Off Ver
    MS Office 2016
    Posts
    11

    Re: Count cells from left to right based on > value

    This is excellent! Thanks so much. I'm sorry, I should have added some more info.

    How could I create a formula for each row? So if I had 100 lines of data and for each line on column G it would have the result for each line.

  6. #6
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,451

    Re: Count cells from left to right based on > value

    Removed: Double posted.
    Dave

  7. #7
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,451

    Re: Count cells from left to right based on > value

    Array enter this in G1 and fill down.

    If you aren’t familiar with array-entered formulas array enter means the formula must be committed from edit mode by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    A
    B
    C
    D
    E
    F
    G
    1
    96
    98
    100
    79
    99
    97
    3
    2
    96
    98
    27
    99
    99
    97
    2

  8. #8
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,922

    Re: Count cells from left to right based on > value

    I think this should work:

    =MATCH(94,A1:F1,-1)

    depending on if you wanted to stop counting when it was exactly 94, you may want to enter in 93.99999 or 94.0001

  9. #9
    Registered User
    Join Date
    11-18-2015
    Location
    Dallas Texas
    MS-Off Ver
    MS Office 2016
    Posts
    11

    Re: Count cells from left to right based on > value

    Ok got it. Tested and works perfect! Thank you so much! You rock

  10. #10
    Registered User
    Join Date
    11-18-2015
    Location
    Dallas Texas
    MS-Off Ver
    MS Office 2016
    Posts
    11

    Re: Count cells from left to right based on > value

    Sorry Greg, just saw your post. Thank you too!

  11. #11
    Registered User
    Join Date
    11-18-2015
    Location
    Dallas Texas
    MS-Off Ver
    MS Office 2016
    Posts
    11

    Re: Count cells from left to right based on > value

    Quote Originally Posted by alansidman View Post
    Here is a VBA solution

    Please Login or Register  to view this content.
    How to install your new code
    • Copy the Excel VBA code
    • Select the workbook in which you want to store the Excel VBA code
    • Press Alt+F11 to open the Visual Basic Editor
    • Choose Insert > Module
    • Edit > Paste the macro into the module that appeared
    • Close the VBEditor
    • Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)


    To run the Excel VBA code:
    • Press Alt-F8 to open the macro list
    • Select a macro in the list
    • Click the Run button
    Thanks for your Help on this one. I have saved this one and this will also come in handy.

  12. #12
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,451

    Re: Count cells from left to right based on > value

    You are welcome. If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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. Replies: 6
    Last Post: 06-26-2017, 09:04 PM
  2. Count blank cells right to left where range is based on column header
    By makmood in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-16-2016, 08:18 PM
  3. Coloring cells to left and right based on cell value
    By KevBotes in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-18-2013, 03:24 AM
  4. Inserting cells to the left based on cell value
    By Judge Dredd in forum Excel General
    Replies: 5
    Last Post: 03-11-2011, 04:39 AM
  5. macro to select cells based on status of cells to left
    By dcbiker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-03-2011, 05:15 PM
  6. Sort based on values of cells to the left
    By okriskao in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2009, 08:49 AM
  7. Count based on data in column to left
    By Nadir Soofi in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-29-2008, 01:40 PM

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