dynamic form pulling only non zero data from a list

swtwtr25

New Member
Joined
Dec 28, 2016
Messages
1
If I have an input table where I select a quantity of certain inputs or I toggle inputs and I want the output form to contain a list of only the items that are greater than zero or toggled yes:

So if this is my list:

dogs - 0
birds - 125
chickens - yes
pigs - no
cats - 0
spiders -16
snakes - 0

my output would only be 3 lines

birds
chickens
spiders

------------------------

but if my input changed to

dogs - 1
birds - 125
chickens - yes
pigs - yes
cats - 0
spiders - 0
snakes - 18

then my output would be

dogs
birds
chickens
pigs
snakes


I don't want blank lines in the output b/c I'd have 300 lines of input of which only 20 lines of output is wanted in a clean fashion.

Thank you in advance for your help!!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,210
3
dogs0 List
birds125 birds125
chickensyes chickensyes
pigsno spiders16
cats0
spiders16
snakes0

<colgroup><col width="64" style="width:48pt" span="5"> </colgroup><tbody>
</tbody>

In D1 enter:

=SUM(COUNTIFS(B2:B8,{">0","yes"}))

In D3 control+shift+enter, not just enter, copy across to E3, and down:

=IF(ROWS($D$3:D3)>$D$1,"",INDEX(A$2:A$8,SMALL(IF(IF(ISNUMBER($B$2:$B$8),$B$2:$B$8>0)+($B$2:$B$8="yes"),ROW(A$2:A$8)-ROW(A$2)+1),ROWS($D$3:D3))))
 
Upvote 0

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
844
May be
Code:
Sub Test()
    Dim arr, arrOut
    Dim i As Long
    Dim j As Long
    
    arr = Range("A1").CurrentRegion.Value
    ReDim arrOut(1 To UBound(arr, 1), 1 To UBound(arr, 2))
    
    For i = LBound(arr, 1) To UBound(arr, 1)
        If Val(arr(i, 2)) > 0 Or LCase(arr(i, 2)) = LCase("yes") Then
            j = j + 1
            arrOut(j, 1) = arr(i, 1)
            arrOut(j, 2) = arr(i, 2)
        End If
    Next i
    
    Range("E1").Resize(j, UBound(arrOut, 2)).Value = arrOut
End Sub
 
Upvote 0

Forum statistics

Threads
1,196,019
Messages
6,012,901
Members
441,739
Latest member
Jeezer

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
Top