Solved

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

Posted on 2014-07-28
3
1,688 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 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

by:
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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now