PC Review


Reply
Thread Tools Rate Thread

Count the number of cells in a range with a string containing a specified substring

 
 
Sisilla
Guest
Posts: n/a
 
      19th Mar 2007
Hello All,

I am trying to search a range to find all the cells that contain a
string with a specified substring. I know that I could do this by
looping through each cell in the range and testing:

For Each rCell In SearchRange.Cells
If InStr(rCell.Value, Substring) <> 0 Then
...

, but I was wondering if there was a faster way of doing this. For
instance, is there some way I could count all the cells that do
contain strings with the specified substring and then limit the loop
iterations to that number? That would save me many iterations if the
cells containing strings with the specified substring are at the top
of the range or if no cell contains a string with the specified
substring. Perhaps the code would look something like this:

HowMany = Application.CountIf(SearchRange,
InStr(SearchRange.Cells.Value, Substring))

I am running Excel 2003 and Visual Basic 6.3. I appreciate any effort
to help me. Thank you in advance for your time and consideration.

Sisilla

 
Reply With Quote
 
 
 
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      19th Mar 2007
Sub routine()
MsgBox (Application.WorksheetFunction.CountIf(Selection, "*e*"))
End Sub


will indicate how many cell in Selection contain an e within them. Adapt as
you wish.


b.t.w works the same way on the worksheet.
--
Gary''s Student
gsnu200711

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Count one character in a string across a range of cells? Shane Devenshire Microsoft Excel Worksheet Functions 1 6th Feb 2009 04:33 PM
RE: Count one character in a string across a range of cells? Gary''s Student Microsoft Excel Worksheet Functions 0 6th Feb 2009 03:39 PM
Count one character in a string across a range of cells? Andrea Microsoft Excel Worksheet Functions 0 6th Feb 2009 03:26 PM
Count the number of cells in a range with a string containing a specified substring Sisilla Microsoft Excel Programming 2 19th Mar 2007 12:01 PM
count substring within a string Joe Blow Microsoft Access 4 5th Dec 2006 12:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:20 AM.