Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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,037 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
[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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

670 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