Looping to count instances across columns and rows

nikhil1101

New Member
Joined
Aug 8, 2017
Messages
1
Hi

I have three columns & 4000 rows with values in each cell that range from 0-60. I would like to could how many times each value occurs exclusively in each row for each column.

e.g

trying to count how many 18s for the 3 rows


row a 18 16 56
row b 60 18 18
roc c 55 18 02

The count for 18 in the scenario above would be 3. I'm assuming this will have to be looped in VB.

Thanks
Nik
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try, this will generate a message box it can be change to put the result in a cell if that is what you want.

Code:
Sub countinstances()
Dim lr As Long
Dim mynum As Double
Dim mycount As Long
lr = Cells(Rows.count, 1).End(xlUp).Row
mynum = Val(InputBox("enter number to count"))
mycount = 0
For x = 1 To lr
    On Error Resume Next
    a = Application.Match(mynum, Range("A" & x & ":C" & x), 0)
    If IsError(a) = False Then
        mycount = mycount + 1
    End If
Next x
MsgBox ("the count is " & mycount)

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,701
Messages
6,126,290
Members
449,308
Latest member
VerifiedBleachersAttendee

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