VBA: Make list from table without header and first column and omit the zeros

Styx

New Member
Joined
Nov 19, 2021
Messages
20
Office Version
  1. 2007
Platform
  1. Windows
Hi All,
I am new on this forum, but I am using a lot of your solutions already, thanks for that!
Now I have an issue for which I can't find an "exact" solution, while my question may sound very familiar.
The solution may be VBA or a formula. I just want a list of every "non zero" from a table.
The original table is 529 rows x35 colums with a header and a leading column, the example below is just for reference.
There will be a lot of zero's in the table, so the list will not be extremely long.
Already played around with Cells(1).CurrenRegion and UBound, but nothing comes near.

Thanks in advance for all the help.

Table-list.xlsm
ABCDEFGHIJ
1abcdehhhh
21hhhh0mmmmnnnnppppresult -->rrrr
32rrrr0sssseeeeffffiiii
43iiii0llll00qqqq
54qqqq0000jjjj
65jjjj0000oooo
76ooooaaaa00ggggaaaa
870bbbb000bbbb
980kkkkcccc00kkkk
10900000mmmm
111000000ssss
12llll
13cccc
14nnnn
15eeee
16pppp
17ffff
18gggg
19
Blad1
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
How about
VBA Code:
Sub styx()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long
   
   Ary = Range("B2:F" & Range("A" & Rows.Count).End(xlUp).Row).Value2
   ReDim Nary(1 To UBound(Ary) * UBound(Ary, 2), 1 To 1)
   
   For r = 1 To UBound(Ary)
      For c = 1 To UBound(Ary, 2)
         If Ary(r, c) <> 0 Then
            nr = nr + 1
            Nary(nr, 1) = Ary(r, c)
         End If
      Next c
   Next r
   Range("I2").Resize(nr, 1).Value = Nary
End Sub
 
Upvote 0
Solution
Hi Fluff,
Extremely fast reaction, thanks!
I'll test it ASAP.
 
Upvote 0
100% Match for this small table, thanks!
Just have to test it in my large table this weekend.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Tested it this weekend, works like a charm !
Thanks again.
 
Upvote 0
Hi
Another option Might be faster
1- keep the duplicates if there is any
VBA Code:
Sub test()
Dim a As Variant
Dim i, ii As Long
a = Range("b2").CurrentRegion
Columns("I").ClearContents
With CreateObject("scripting.dictionarY")
    For i = 2 To UBound(a)
        For ii = 2 To UBound(a, 2)
                If a(i, ii) <> 0 And Not .exists(a(i, ii)) Then
            .Add .Count, a(i, ii)
            End If
    Next: Next
    Range("I2").Resize(.Count).Value = Application.Transpose(.items)
    End With
End Sub

2- Remove duplicates

VBA Code:
Sub test1()
Dim a As Variant
Dim i, ii As Long
Columns("I").ClearContents
a = Range("b2").CurrentRegion
With CreateObject("scripting.dictionarY")
    For i = 2 To UBound(a)
        For ii = 2 To UBound(a, 2)
            If a(i, ii) <> 0 Then
                If a(i, ii) <> 0 And Not .exists(a(i, ii)) Then
                .Add a(i, ii), ""
            End If: End If
    Next: Next
    Range("I2").Resize(.Count).Value = Application.Transpose(.keys)
    End With
End Sub
 
Upvote 0
thanks for your answer, I'll test this one too.
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,891
Members
449,194
Latest member
JayEggleton

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