How to write a counting Macro/VBA that looks for a certain Value

alanmur

New Member
Joined
Dec 22, 2007
Messages
6
I am hoping someone can help me with this. Every month i run some reports were i have to count the number of entries in a column (F) that meet certain criteria in an excel spreadsheet. Then i enter the counted value into another cell for reporting. I know i can use and have the countif formula but was hoping someone could point me in a direction that i could run a macro on a spreadsheet and have the value put in a certain cell. Also there are 15 different types of entries i do this for. Thanks for any help you can offer.

W1 1-May-13 2442195 956 MEETING
W1 1-May-13 2442195 958 SHIFT START UP
W1 1-May-13 2442195 960 CLEAN UP
W1 1-May-13 2442382 951 NPP - LUNCH 1
W1 2-May-13 2442386 956 MEETING
W1 2-May-13 2443175 951 NPP - LUNCH 1
W1 2-May-13 2443175 13 MECHANICAL BREAKDOWN
W1 2-May-13 2443175 13 MECHANICAL BREAKDOWN
W1 3-May-13 2443774 956 MEETING
W1 3-May-13 2443970 951 NPP - LUNCH 1
W1 6-May-13 2441231 951 NPP - LUNCH 1
W1 6-May-13 2441231 960 CLEAN UP
W1 6-May-13 2441231 960 CLEAN UP
W1 6-May-13 2441231 958 SHIFT START UP
W1 6-May-13 2441231 956 MEETING
W1 7-May-13 2443971 956 MEETING
W1 7-May-13 2443971 958 SHIFT START UP
W1 7-May-13 2438683 951 NPP - LUNCH 1
W1 7-May-13 2438687 10 OTHER PROCESS FAILURE
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Can you record a macro, then make a pivot table to do the counts...
Then record another macro that copies the values of the pivot to your reporting sheet?
 
Upvote 0
You can implement COUNTIF pretty easily in VBA, e.g.,

Rich (BB code):
Sub COUNTIF()
    For r = 1 To 15
        n = Evaluate("COUNTIF(ReferenceSheet!F:F,""" & Cells(r, 1) & """)")
        Cells(r, 2) = n
    Next
End Sub
You might need to change the code highlighted in red.

Hope this helps,

Chris.
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,433
Members
448,897
Latest member
ksjohnson1970

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