Excel Macro for counting values

I have a csv file which has multiple columns. The column headers are in row 1 and each column is called Scheduled or Actual.
In each column, there is a time record. I need an excel macro that will count the total number of Scheduled times and the total number of Actual times in the file. The result can be written to the end of the file as follows;
Scheduled Times: 40
Actual Times: 25

I have attached a sample file. In this file there are 40 Scheduled times and 25 Actual times.
Times.csv
dm7733Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
Any particular reason you want to do this with macro as you can easily do this with formula which is..

=SUMPRODUCT((A1:G1="Scheduled")*(A2:G23<>"")) for schedule

and

=SUMPRODUCT((A1:G1="Scheduled")*(A2:G23<>"")) for actual..

Your workbook for reference...

Saurabh...
Time.csv
0
[ fanpages ]IT Services ConsultantCommented:
0
dm7733Author Commented:
Hi Saurabh, what is the vba equivalent code for this as I'm looking to use this within a macro?
0
Saurabh Singh TeotiaCommented:
You can simple use this code and it will do what you are looking for...

Sub chckvalues()
    Dim lrow As Long
    Dim sc As Long, ac As Long

    lrow = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

    sc = Application.Evaluate("=SUMPRODUCT((A1:G1=""Scheduled"")*(A2:G" & lrow & "<>""""))")

    ac = Application.Evaluate("=SUMPRODUCT((A1:G1=""Actual"")*(A2:G" & lrow & "<>""""))")

    Cells(5, "m").Value = sc
    Cells(6, "m").Value = ac

End Sub

Open in new window


Saurabh...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.