+ Reply to Thread
Results 1 to 4 of 4

First and last column numbers with non-zero cells in a range

Hybrid View

  1. #1
    Registered User
    Join Date
    01-02-2009
    Location
    Massachusetts, US
    MS-Off Ver
    Excel 2007
    Posts
    2

    First and last column numbers with non-zero cells in a range

    I'm trying to figure out how to get the column numbers for the first and last non-zero cells in a range. It seems pretty easy to get the actual values using some tips I found on here, but getting the actual column numbers eludes me.

    Each cell represents a week, with the first non-zero being the start week and the last non-zero being the end week. All cell values are integers.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    If rng is a row vector, then

    =MATCH(TRUE, INDEX(rng<>0, 0), 0) + COLUMN(rng) - 1 returns the column of the first non-zero value, and

    =MATCH(2, INDEX(1/(rng<>0), 0), 1) + COLUMN(rng) - 1 returns the last
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    Here's another option?

    If your dates are in the range B1:H1

    =SUMPRODUCT(--(B1:H1=MIN(B1:H1))*(COLUMN(B1:H1)))

    =SUMPRODUCT(--(B1:H1=MAX(B1:H1))*(COLUMN(B1:H1)))
    Last edited by oldchippy; 01-02-2009 at 03:34 PM. Reason: Edit my range to match
    oldchippy
    -------------


    Blessed are those who can give without remembering and take without forgetting

    If you are happy with the help you have received, please click the <--- STAR icon on the left - Thanks.

    Click here >>> Top Excel links for beginners to Experts

    Forum Rules >>>Please don't forget to read these

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    If you're happy using array formulas (must be confirmed with Ctrl+Shift+Enter), you could use

    =MIN(IF(rng<>0, COLUMN(rng))) for the first and

    =MAX(IF(rng<>0, COLUMN(rng))) for the last

+ 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