Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Count the number of occurrences of a substring in Column A entries using VBA

Posted on 2014-07-28
3
Medium Priority
?
2,118 Views
Last Modified: 2014-07-29
Dear Experts:

I got thousands of entries in Column A. Part of the string in these entries can be 99-999-99-99 such as ...

P:\\Graphics\\MyFolder\\99\\99-999-99-99.tif

I would like a macro ...
... to count the number of entries in Column A in the current worksheet where the sub-string 99-999-99-99 occurs.

The result is to be displayed in D5 of the current worksheet.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
3 Comments
 
LVL 18

Assisted Solution

by:krishnakrkc
krishnakrkc earned 600 total points
ID: 40226071
Hi

Do you really need a macro for this ?

=COUNTIF(A:A,"*99-999-99-99*")

would suffice.

Kris
0
 
LVL 13

Accepted Solution

by:
duncanb7 earned 1400 total points
ID: 40226087
it should be

=CountIf(A:A, "*" &  "99-999-99-99" & "*")

you can try this macro

Duncan
Sub test()
ActiveSheet.Activate
Dim str As String
str = "99-999-99-99"
ActiveSheet.Range("D5") = Application.WorksheetFunction.CountIf(ActiveSheet.Range("A:A"), "*" & str & "*")
ActiveSheet.Range("D5").Select
End Sub

Open in new window

0
 

Author Closing Comment

by:AndreasHermle
ID: 40226363
Dear both,

both codes / formulas work just fine. I suggest splitting the points 350:150

Thank you very much for your great and swift support. I really appreciate it. Regards, Andreas
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question