PC Review


Reply
Thread Tools Rate Thread

Checking if a cell contains a string that is not case sensitive

 
 
Colin Hempsey
Guest
Posts: n/a
 
      9th May 2008
I am trying to count how many times a specific string "abc" forms part of a
cell in a spreadsheet.

For example

abcgfd, abcdse, efgabc would be vaild and I would like to count these

abdcef, bcadef, cbaeds would not be valid and I would not want to count these.

Can anyone help point me in the right direction?

Thanks.
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      9th May 2008
You need to use find with the lookat:=xlpart. See VBA help "FindNext Method"

"Colin Hempsey" wrote:

> I am trying to count how many times a specific string "abc" forms part of a
> cell in a spreadsheet.
>
> For example
>
> abcgfd, abcdse, efgabc would be vaild and I would like to count these
>
> abdcef, bcadef, cbaeds would not be valid and I would not want to count these.
>
> Can anyone help point me in the right direction?
>
> Thanks.

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      9th May 2008
One way (checks for any case also)

Sub countpart()
For Each c In Range("g2:g22")
If InStr(UCase(c), "ABC") Then ctr = ctr + 1
'If InStr(c, "abc") Then ctr = ctr + 1'for abc ONLY (no case check)
Next c
MsgBox ctr
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Colin Hempsey" <(E-Mail Removed)> wrote in message
news:3E2E1182-0C1E-4D02-B291-(E-Mail Removed)...
>I am trying to count how many times a specific string "abc" forms part of a
> cell in a spreadsheet.
>
> For example
>
> abcgfd, abcdse, efgabc would be vaild and I would like to count these
>
> abdcef, bcadef, cbaeds would not be valid and I would not want to count
> these.
>
> Can anyone help point me in the right direction?
>
> Thanks.


 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      9th May 2008
This count you are doing... it is in a single cell, right? If so, this
function should do what you want...

Function CountTextInCell(CellText As String, TextToCount As String) As Long
If Len(CellText) = 0 Then Exit Function
CountTextInCell = (Len(CellText) - Len(Replace(CellText, TextToCount, _
"", , , vbTextCompare))) / Len(TextToCount)
End Function

Just pass in the text from the cell. For example...

Sub Test()
MsgBox CountTextInCell(Sheet2.Range("A1").Value, "abc")
End Sub

Rick


"Colin Hempsey" <(E-Mail Removed)> wrote in message
news:3E2E1182-0C1E-4D02-B291-(E-Mail Removed)...
>I am trying to count how many times a specific string "abc" forms part of a
> cell in a spreadsheet.
>
> For example
>
> abcgfd, abcdse, efgabc would be vaild and I would like to count these
>
> abdcef, bcadef, cbaeds would not be valid and I would not want to count
> these.
>
> Can anyone help point me in the right direction?
>
> Thanks.


 
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
Are OL2007 rules that do string matches case sensitive? =?Utf-8?B?SVRmb3IyMA==?= Microsoft Outlook Discussion 0 31st May 2007 11:21 PM
Un-Checking Case sensitive Box in Explorer Search Gets Un-expected Results Nehmo Windows XP General 0 15th Oct 2005 08:04 PM
Un-Checking Case sensitive Box in Explorer Search Gets Un-expected Results Nehmo Windows XP Help 0 15th Oct 2005 08:04 PM
Case Sensitive String Comparisons =?Utf-8?B?VGF0YWthdQ==?= Microsoft Access Form Coding 7 14th Oct 2005 05:40 PM
2 String values equal each other - Case Sensitive Tony_VBACoder Microsoft Access VBA Modules 6 7th Jun 2004 06:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:49 AM.