Solved

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

Posted on 2014-07-28
1,874 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
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
3 Comments

LVL 18

Assisted Solution

krishnakrkc earned 150 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

duncanb7 earned 350 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
``````
0

Author Closing Comment

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

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Suggested Courses
Course of the Month4 days, 11 hours left to enroll

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

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