Solved

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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

830 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