+ Reply to Thread
Results 1 to 3 of 3

If cell is 0, reference next row of cells

  1. #1
    Registered User
    Join Date
    09-07-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    2

    If cell is 0, reference next row of cells

    I'm listing 50 rows x 8 columns of cells (defined 'allhazards')

    However each cell in myhazards is referencing other sheets and contain 0's where there is no text to be referenced.

    When I list myhazards in a single column using this formula:

    =INDEX(allhazards,1+INT((ROW($A1)-1)/COLUMNS(allhazards)),MOD(ROW($A1)-1+COLUMNS(allhazards),COLUMNS(allhazards))+1)
    (then drag down the column to get all of the cells from 'allhazards')

    How do I implement this:

    if cell in 'allhazards' is 0, do not reference this, move to next row
    ...then reference next row's columns until cell is 0, then move to next row
    ...keep doing this until there are no rows left to be referenced


    eg. if 'allhazards' contained these cells (eg. 2 rows x 8 columns):
    hello how are 0 0 0 0 0
    good 0 0 0 0 0 0 0

    It should produce this:
    hello
    how
    are
    good

    but not this:
    hello
    how
    are
    0
    0
    0
    0
    0
    good
    0
    0
    0
    0
    0
    0
    0

  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: If cell is 0, reference next row of cells

    I've made a quick example with the help of helper cells - see attached below.

    Basically converts your allhazards matrix into a series of
    1, 2, 3, 4;
    5, 6, 7, 8
    I call this the Item#
    Cell D6: =SMALL(INDEX(COLUMN(allhazards)-MIN(COLUMN(allhazards))+1+COLUMNS(allhazards)*(ROW(allhazards)-MIN(ROW(allhazards)))+(allhazards=0)*1000,0),C6)
    Note: C6 is 1, C7 is 2, C8 is 3, etc.

    then get's rid of the ones that are 0 - and uses SMALL to identify the item of significance and convert the item# into rows/columns for use in INDEX.
    E6: Row_num: =TRUNC(D6/COLUMNS(allhazards))+1
    F6: Col_num: =MOD($D6,COLUMNS(allhazards))
    B6: Output: =IFERROR(INDEX(allhazards,E6,F6),"")


    Should be fairly easy to make this into a mega formula yourself.
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: If cell is 0, reference next row of cells

    Also, cross-post: http://www.mrexcel.com/forum/excel-q...-next-row.html
    and really similar and related post: http://www.excelforum.com/excel-prog...-next-row.html

+ 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: 3
    Last Post: 09-02-2015, 01:21 PM
  2. Drag a formula right one cell, reference cell jumps four cells?
    By phutai1104 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-01-2014, 04:00 AM
  3. [SOLVED] Highlight cells between 1 reference cell and last filled cell on Row
    By dleeds in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-06-2013, 05:10 PM
  4. Drag a formula down one cell, reference cell jumps down four cells?
    By rrbest in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-13-2013, 10:59 AM
  5. Drag a formula right one cell, reference cell jumps right 2 cells?
    By mukulhanda in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-13-2013, 12:10 AM
  6. Replies: 1
    Last Post: 12-15-2012, 08:42 AM
  7. Replies: 2
    Last Post: 10-28-2007, 10:36 PM

Tags for this Thread

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