+ Reply to Thread
Results 1 to 9 of 9

Return all non-blank cells from a range

  1. #1
    Registered User
    Join Date
    11-29-2012
    Location
    Europe
    MS-Off Ver
    Excel 2003, 2007
    Posts
    26

    Return all non-blank cells from a range

    Hi,

    I want to apply pb71's solution but horizontally instead. I tried applying the same formula except I inverted the rows/columns etc but it doesn't seem to be working. (Please see attached)

    Does anyone know what I'm soing wrong here?

    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Return all non-blank cells from a range

    Hi,

    You haven't correctly adjusted the COLUMN part at the end. In the original (vertical) version, the function of the ...+ROW(D1) is to give a value of 1 (since ROW(D1)=1) and then, when copied down, to give successively ...+ROW(D2) (=2), ...+ROW(D2) (=3), etc., etc.

    So when you changed this to a 'horizontal' version, you correctly substituted the COLUMN function for the ROW function, but you forgot to ensure that, for your first case, this would return a value of 1. For this, you simply need to ensure that you have a reference in the COLUMN function which is in column A, e.g. A1:

    =IFERROR(INDEX(19:19,,SMALL(INDEX(NOT(ISBLANK($K$19:$AC$19))*COLUMN($K$19:$AC$19),,0),COUNTBLANK($K$19:$AC$19)+COLUMN(A1))),"")

    When dragged to the right, this will then produce ...+COLUMN(B1) (=2), ...+COLUMN(C1) (=3), etc., etc.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Return all non-blank cells from a range

    Not real clear what you want to do.

    I'm guessing that you want to take the data in the horizontal range K19:AA19 and rearrange it into a contiguous vertical range?

    If so, try this...

    This array formula** entered in H2:

    =IFERROR(INDEX($19:$19,SMALL(IF(K$19:AA$19<>"",COLUMN(K$19:AA$19)),ROWS(H$2:H2))),"")

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    Copy down until you get blanks.
    Last edited by Tony Valko; 05-30-2013 at 09:25 AM.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Registered User
    Join Date
    11-29-2012
    Location
    Europe
    MS-Off Ver
    Excel 2003, 2007
    Posts
    26

    Re: Return all non-blank cells from a range

    Quote Originally Posted by XOR LX View Post
    Hi,

    You haven't correctly adjusted the COLUMN part at the end. In the original (vertical) version, the function of the ...+ROW(D1) is to give a value of 1 (since ROW(D1)=1) and then, when copied down, to give successively ...+ROW(D2) (=2), ...+ROW(D2) (=3), etc., etc.

    So when you changed this to a 'horizontal' version, you correctly substituted the COLUMN function for the ROW function, but you forgot to ensure that, for your first case, this would return a value of 1. For this, you simply need to ensure that you have a reference in the COLUMN function which is in column A, e.g. A1:

    =IFERROR(INDEX(19:19,,SMALL(INDEX(NOT(ISBLANK($K$19:$AC$19))*COLUMN($K$19:$AC$19),,0),COUNTBLANK($K$19:$AC$19)+COLUMN(A1))),"")

    When dragged to the right, this will then produce ...+COLUMN(B1) (=2), ...+COLUMN(C1) (=3), etc., etc.

    Regards
    Thanks for your help!
    Now why didn't that occur to me...

  5. #5
    Registered User
    Join Date
    11-29-2012
    Location
    Europe
    MS-Off Ver
    Excel 2003, 2007
    Posts
    26

    Re: Return all non-blank cells from a range

    Is there a way I can mark the thread as 'solved'? Or is this for the administrator?

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Return all non-blank cells from a range

    Quote Originally Posted by XOR LX View Post
    For this, you simply need to ensure that you have a reference in the COLUMN function which is in column A, e.g. A1:

    =IFERROR(INDEX(19:19,,SMALL(INDEX(NOT(ISBLANK($K$19:$AC$19))*COLUMN($K$19:$AC$19),,0),COUNTBLANK($K$19:$AC$19)+COLUMN(A1))),"")

    When dragged to the right, this will then produce ...+COLUMN(B1) (=2), ...+COLUMN(C1) (=3), etc., etc.

    Regards
    Better to use the COLUMNS or ROWS function (whichever applies to the particular application).

    You would use the reference of the first cell the formula is entered in.

    COLUMNS($D2:D2)
    COLUMNS($X27:X27)

    ROWS(D$2:D2)
    ROWS(X$27:X27)

    Using the COLUMNS/ROWS function makes the formula a bit more robust without adding any undesirable inefficiency.

    Using your formula with the COLUMN function, insert a new column A and see what happens to the results.

  7. #7
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Return all non-blank cells from a range

    Thanks, Tony, but this was not actually 'my' formula and I was merely pointing out to the user the error that he'd made when attempting to adapt the formula he'd taken from another link (in which the ROW, not ROWS method was used).

    Having said that, I possibly could have spent a bit more time on the thread and perhaps included something similar to that which you've just explained (of which I'm fully aware), but since you've just done so I don't need to now!

    Cheers

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Return all non-blank cells from a range

    Just tryin' to help!

  9. #9
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Return all non-blank cells from a range

    I know! And I'm grateful! Just tired so not seeing as much as you

+ 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