Bringing Values to Top of Column Formula?

jwillits

New Member
Joined
Jul 10, 2018
Messages
36
Office Version
  1. 2010
Platform
  1. Windows
I assume I need some ARRAY formula, but not sure how to do it. I have blank cells and cells with a value in column C and Column D is the formula I am trying to make. I want to move all values in Column C to the top of Column D in the order that they are in in Column C with blank cells being on the very bottom. Here is an example

A


PRODUCT
B


DATE
C

KNOWN PURCHASE FORMULA
D

FORMULA TO BRING TO TOP OF LIST
APPLE 22247/25EGG1013
EGG 10138/23EGG 1013PEAR 1321
GRAPE 31214/22
PEAR 13212/22PEAR 1321

<tbody>
</tbody>

Any help is appreciated.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
This one might not be the most elegant way to do it but it's the first I came up with:

=INDEX($C$2:$C$15,AGGREGATE(15,6,(NOT(ISBLANK($C$2:$C$15))*ROW($C$2:$C$15)/--NOT(ISBLANK($C$2:$C$15))),ROWS($C$2:C2))-1)

INDEX returns the value from the given range and the AGGREGATE is used as SMALL to return the smallest row number where the value is not blank. The division part is used to cause 0/0 errors to get rid of the zeroes. Since the AGGREGATE is returning row numbers and my INDEX range is not starting from the top of the C column, I need to subtract the header row from my row number. I'm taking the easy way out here by entering the header row number here. Usually you'd use yet another ROW or ROWS for that too.
 
Upvote 0
This one might not be the most elegant way to do it but it's the first I came up with:

=INDEX($C$2:$C$15,AGGREGATE(15,6,(NOT(ISBLANK($C$2:$C$15))*ROW($C$2:$C$15)/--NOT(ISBLANK($C$2:$C$15))),ROWS($C$2:C2))-1)

INDEX returns the value from the given range and the AGGREGATE is used as SMALL to return the smallest row number where the value is not blank. The division part is used to cause 0/0 errors to get rid of the zeroes. Since the AGGREGATE is returning row numbers and my INDEX range is not starting from the top of the C column, I need to subtract the header row from my row number. I'm taking the easy way out here by entering the header row number here. Usually you'd use yet another ROW or ROWS for that too.


Hmm, when I plug the column I am using into this formula, it is putting the value right beside it instead of bringing it to the top of the column. Where am I going wrong?
 
Last edited:
Upvote 0
Can't tell exactly without seeing the case.

Make sure the ranges are locked correctly i.e. the "$" signs are in right places: All the other ranges are completely locked but on the ROWS function only the first row is locked). Enter the formula to your D2 and copy down. If your data is set up exactly as it is in your example the formula seems to work correctly.
 
Upvote 0
Can't tell exactly without seeing the case.

Make sure the ranges are locked correctly i.e. the "$" signs are in right places: All the other ranges are completely locked but on the ROWS function only the first row is locked). Enter the formula to your D2 and copy down. If your data is set up exactly as it is in your example the formula seems to work correctly.

This is the exact formula I am using.

=INDEX($N$2:$N$999,AGGREGATE(15,6,(NOT(ISBLANK($N$2:$N$999))*ROW($N$2:$N$999)/--NOT(ISBLANK($N$2:$N$999))),ROWS($N$2:N2))-1)

All I did was change the C's in your formula to N's because in my spreadsheet the values I want to pull from are in column N. Also, I change the range to 999 as depicted by the pink in my formula. Ideally, I would want the entire column, N:N, but I can just make the range 2:100000 if necessary. The only number changing as i drag down is what is listed in red, as it changes from N2, N3, N4, and so on. Do you see any issues in this formula I am using or what I am doing?
 
Upvote 0
Your formula is absolutely correct and works like a charm. But I guess I finally figured out the reason why it's not working on your workbook but works well on mine: You have formulas in your cells. When the cells have formulas they are not blank even if the value shows "". This means the ISBLANK returns FALSE for every cell. The easiest workaround would be to check that the LEN of the cell value is >0. Because this returns TRUE for every row we're looking for instead of every row we're not interested in as was the case with ISBLANK we can get rid of the NOTs as well.

So try

=INDEX($N$2:$N$999,AGGREGATE(15,6,((LEN($N$2:$N$999)>0)*ROW($N$2:$N$999)/--(LEN($N$2:$N$999)>0)),ROWS($N$2:N2))-1)
 
Upvote 0
Your formula is absolutely correct and works like a charm. But I guess I finally figured out the reason why it's not working on your workbook but works well on mine: You have formulas in your cells. When the cells have formulas they are not blank even if the value shows "". This means the ISBLANK returns FALSE for every cell. The easiest workaround would be to check that the LEN of the cell value is >0. Because this returns TRUE for every row we're looking for instead of every row we're not interested in as was the case with ISBLANK we can get rid of the NOTs as well.

So try

=INDEX($N$2:$N$999,AGGREGATE(15,6,((LEN($N$2:$N$999)>0)*ROW($N$2:$N$999)/--(LEN($N$2:$N$999)>0)),ROWS($N$2:N2))-1)

Ah, yep, learned something new. This one works perfect. Thanks very much.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,853
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top