Finding the most occurrences of a value in a data set, using VBA.

Technology

New Member
Joined
Apr 29, 2021
Messages
25
Office Version
  1. 365
Platform
  1. Windows
With this data starting at A1, how would we go about finding which column has the most occurrences of 0's. Using VBA function, place the result in A25.

738636
169425
51010462
176706
156397
178816
280602
7510130
859940
643242
847669
641431
230884
035476
710083
418396
4111035
730414
366961
823668
0011012
529437
573816
 
Thank you, I would prefer that the code stated that just C based on the data had the most zeros compared to the other columns. Maybe having a count of each column then the code selecting the highest value. I'm not sure the best way of solving this one but I just want to say that I really appreciate your help. I'm definitely learning.
I did not get why you were saying I would prefer that the code stated that just C based on the data had the most zeros compared to the other columns when A and F have same count of zeros. Any other specific criteria?
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I would prefer that the code stated that just C based on the data had the most zeros compared to the other columns.
It does!
Here is your original sample data after the code has been run.
Is there anything about this result that does not match your requirement?

Technology.xlsm
ABCDEF
1738636
2169425
351010462
4176706
5156397
6178816
7280602
87510130
9859940
10643242
11847669
12641431
13230884
14035476
15710083
16418396
174111035
18730414
19366961
20823668
210011012
22529437
23573816
24
25C
Sheet2
 
Upvote 0
As a starter :​
VBA Code:
Sub Demo1()
          Dim N&(), V, C%, M&
    With [A1].CurrentRegion.Columns
        ReDim N(1 To .Count)
            V = Evaluate("IF({1},CHAR(64+COLUMN(" & .Rows(1).Address & ")))")
        For C = 1 To .Count:  N(C) = Application.CountIf(.Item(C), 0):  Next
            M = Application.Max(N)
        For C = 1 To .Count
            If N(C) < M Then V(C) = False
        Next
            V = Filter(V, False, False)
            If UBound(V) > -1 Then Cells(.Rows.Count + 2, 1).Resize(, UBound(V) + 1).Value2 = V
    End With
End Sub
 
Upvote 0
It does!
Here is your original sample data after the code has been run.
Is there anything about this result that does not match your requirement?

Technology.xlsm
ABCDEF
1738636
2169425
351010462
4176706
5156397
6178816
7280602
87510130
9859940
10643242
11847669
12641431
13230884
14035476
15710083
16418396
174111035
18730414
19366961
20823668
210011012
22529437
23573816
24
25C
Sheet2
Thank you! @Peter_SSs

That's correct! I am unsure of how to obtain the code for that, though. I don't seem to have the ability to add-in L2BB.
 
Upvote 0
Like in post #13 !​
Solution belongs to good reader …​
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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