VBA to count numbers between columns

aaaaa34

Board Regular
Joined
Feb 25, 2014
Messages
62
Hello guys,
I'd like to ask your help for VBA to count numbers between columns Q:Z columns in which rows have values more than three.
In the attached file, you will see there are three and more numbers in Rows no.3-4-9-11-12-13-15-17-18-21
I want to know these numbers how many times are written in these rows.
Please have a look into the attached file, you will see (desired) result in the worksheet.

File: Book1.xlsx (Click to "Download" in right-up corner of opened page)

Thank you so much for your interest.
 
Last edited:
Ok, realised my mistake in the original, this will also cater for no rows having 3 or more values
VBA Code:
Sub aaaa34()
   Dim Ary As Variant
   Dim r As Long, c As Long
   
   Ary = Range("Q2:Z" & Range("Q" & Rows.Count).End(xlUp).Row).Value2
   With CreateObject("scripting.dictionary")
      For r = 1 To UBound(Ary)
         If Ary(r, 3) <> "" Then
            For c = 1 To UBound(Ary, 2)
               If Ary(r, c) = "" Then Exit For
               .Item(Ary(r, c)) = .Item(Ary(r, c)) + 1
            Next c
         End If
      Next r
      If .Count > 0 Then Range("AB2").Resize(.Count, 2).Value = Application.Transpose(Array(.Keys, .Items))
   End With
End Sub
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
yes, exactly, I found out it in this line, Fluff
VBA Code:
   Ary = Range("Q2:Z" & Range("Q" & Rows.Count).End(xlUp)).Value2
I changed as "Q2:Z1000" and everything is fine now.
Thanks a lot CEO
 
Upvote 0
If you add the .row as shown in post#11 then it will work, regardless of how many rows of data you have.
 
Upvote 0
Ah your last edit is super cool
now everything is fine, Boss
Thank you, thanks a lot!!!!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,773
Messages
6,121,468
Members
449,033
Latest member
Kcolwell16

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