list values above 0 in a specific order

HMX180

New Member
Joined
Jan 22, 2025
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I'm trying to come up with the folowing results. I have a list of items, and corresponding values. I'm attempting to find only the values above 0, but list them as shown (the items and the values need to be listed from the bottom up). Looking for a formula to make this happen.
1737554842964.png
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try:
Excel Formula:
=FILTER(A1:A6,B1:B6>0)
 
Upvote 0
Cubist,

That was my first thought too, but I cannot figure out how to get that so that the last populated item in the original data (row 5) lines up with the last item of the filter, like they asked for and showed in their example. The only way I can think of is to use VBA.
 
Upvote 0
There are ways to do it. I found it odd that the OP didn't leave enough space for for it to spill when all of them are true i.e. I would expect the last row to be on F6. So I wanted to start something to get their feedback.
Book1
ABCD
1Item A200 
2Item B800
3Item C0
4Item D0Item A
5Item E100Item B
6Item F0Item E
Sheet5
Cell Formulas
RangeFormula
D1:D6D1=VSTACK(TEXTSPLIT(REPT(" ",ROWS(A1:A6)-COUNTIFS(B1:B6,">0")-1),," "),FILTER(A1:A6,B1:B6>0))
Dynamic array formulas.
 
Upvote 0
This seems to work.

Book12
ABCDEFG
1ITEM A200 
2ITEM B800
3ITEM C0ITEM A200
4ITEM D0ITEM B800
5ITEM E100ITEM E100
6ITEM F0
Sheet1
Cell Formulas
RangeFormula
E1:E5E1=LET(l,MAX((B1:B6>0)*ROW(B1:B6)),f,FILTER(A1:A6,B1:B6>0),SORT(EXPAND(f,l,,"")))
G3:G5G3=XLOOKUP(E3:E5,A1:A6,B1:B6)
Dynamic array formulas.
 
Upvote 0

lrobbo314

That will work only if the column A is already sorted. If you swap Item B and A, it'll return Item A then B.
 
Upvote 0
Cubist, it looks like you are off one row.
They want the last row in the "new range" to match the last row in the original range with a value greater than 0.

Here is a very brute-force VBA method that seems to do exactly what they asked for.
VBA Code:
Sub MyCopyData()

    Dim lr As Long
    Dim r As Long
    Dim fr As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column B with data
    lr = Cells(Rows.Count, "B").End(xlUp).Row
    
'   Loop from last row up to first row backwards
    For r = lr To 1 Step -1
'       Check to see if column B is greater than 0
        If Cells(r, "B") > 0 Then
'           See if found row has been set yet (if not, set it, otherwise subtract 1)
            If fr = 0 Then
                fr = r
            Else
                fr = fr - 1
            End If
'           Populate columns F and H
            Cells(fr, "F").Value = Cells(r, "A").Value
            Cells(fr, "H").Value = Cells(r, "B").Value
        End If
    Next r
        
    Application.ScreenUpdating = True
    
End Sub

1737562041343.png


Though I would love to see a formula method!
 
Upvote 0
It wasn't clear to me that was the requirement, but here's the updated version:
Book1
ABCF
1Item A200 
2Item B800
3Item C0Item A
4Item D0Item B
5Item E100Item E
6Item F0
Sheet5
Cell Formulas
RangeFormula
F1:F5F1=LET(v,VSTACK(EXPAND("",ROWS(A1:A6),,""),FILTER(A1:A6,B1:B6>0)),DROP(v,ROWS(v)-XMATCH(TRUE,B1:B6>0,,-1)))
Dynamic array formulas.
 
Upvote 0
Another option

Fluff.xlsm
ABCDEFGH
1Item 1200  
2Item 2800
3Item 30Item 1200
4Item 40Item 2800
5Item 5100Item 5100
6Item 60
Sheet5
Cell Formulas
RangeFormula
F1:F5F1=LET(r,ROW(XLOOKUP(TRUE,(B1:B6>0),B1:B6,,,-1)),f,FILTER(A1:A6,B1:B6>0),rf,ROWS(f),IF(r=rf,f,VSTACK(EXPAND("",r-rf,,""),f)))
H1:H5H1=XLOOKUP(F1#,A1:A6,B1:B6,"")
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,226,114
Messages
6,189,052
Members
453,522
Latest member
Seeker2025

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