Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default counting appearances of a short string within strings in a whole worksheet

Hi group members,

After copying a large amount of text from a pdf (I unfortunately have
no other way to import those data), I need to count the appearances of
the string "mrs" in the whole worksheet. After trying several options,
I am desperate and would like to ask you for help.

Imagine all data togethe in a cell (all text, sometimes figures).
I now want to count the string "mrs" within this string, but not only
in one cell, but in all cells.

Thanks a lot, if you would help me with this.

Cheers,

Rico

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,718
Default counting appearances of a short string within strings in a whole worksheet

You'd need a macro. See if this does it:

Sub TestIt()
Dim StrCount As Long
StrCount = CountSubStrings("mrs", Cells)
MsgBox StrCount
End Sub

Function CountSubStrings(Strg As String, Rg As Range) As Long
Dim Cell As Range
Dim StrLeng As Integer
Dim CellCount As Long, TotalCount As Long
Dim CellVal As String, ShortStr As String
StrLeng = Len(Strg)
On Error GoTo ExitThis
For Each Cell In Rg.SpecialCells(xlCellTypeConstants, xlTextValues)
CellVal = Cell.Value
ShortStr = Replace(CellVal, Strg, "", , , vbTextCompare)
CellCount = (Len(CellVal) - Len(ShortStr)) / StrLeng
TotalCount = TotalCount + CellCount
Next
CountSubStrings = TotalCount
ExitThis:
End Function


--
Jim
"ricowyder" wrote in message
oups.com...
| Hi group members,
|
| After copying a large amount of text from a pdf (I unfortunately have
| no other way to import those data), I need to count the appearances of
| the string "mrs" in the whole worksheet. After trying several options,
| I am desperate and would like to ask you for help.
|
| Imagine all data togethe in a cell (all text, sometimes figures).
| I now want to count the string "mrs" within this string, but not only
| in one cell, but in all cells.
|
| Thanks a lot, if you would help me with this.
|
| Cheers,
|
| Rico
|


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 208
Default counting appearances of a short string within strings in a whole w

Do you need to count the number of cells containing "mrs" or every occurences
or "mrs", counting each occurences in every cell ?
--
Regards,
Luc.

"Festina Lente"


"ricowyder" wrote:

Hi group members,

After copying a large amount of text from a pdf (I unfortunately have
no other way to import those data), I need to count the appearances of
the string "mrs" in the whole worksheet. After trying several options,
I am desperate and would like to ask you for help.

Imagine all data togethe in a cell (all text, sometimes figures).
I now want to count the string "mrs" within this string, but not only
in one cell, but in all cells.

Thanks a lot, if you would help me with this.

Cheers,

Rico


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default counting appearances of a short string within strings in a whole worksheet

Thanks Jim. Exactly what I needed. Works perfect.

Regards,

Rico

Jim Rech wrote:
You'd need a macro. See if this does it:

Sub TestIt()
Dim StrCount As Long
StrCount = CountSubStrings("mrs", Cells)
MsgBox StrCount
End Sub

Function CountSubStrings(Strg As String, Rg As Range) As Long
Dim Cell As Range
Dim StrLeng As Integer
Dim CellCount As Long, TotalCount As Long
Dim CellVal As String, ShortStr As String
StrLeng = Len(Strg)
On Error GoTo ExitThis
For Each Cell In Rg.SpecialCells(xlCellTypeConstants, xlTextValues)
CellVal = Cell.Value
ShortStr = Replace(CellVal, Strg, "", , , vbTextCompare)
CellCount = (Len(CellVal) - Len(ShortStr)) / StrLeng
TotalCount = TotalCount + CellCount
Next
CountSubStrings = TotalCount
ExitThis:
End Function


--
Jim
"ricowyder" wrote in message
oups.com...
| Hi group members,
|
| After copying a large amount of text from a pdf (I unfortunately have
| no other way to import those data), I need to count the appearances of
| the string "mrs" in the whole worksheet. After trying several options,
| I am desperate and would like to ask you for help.
|
| Imagine all data togethe in a cell (all text, sometimes figures).
| I now want to count the string "mrs" within this string, but not only
| in one cell, but in all cells.
|
| Thanks a lot, if you would help me with this.
|
| Cheers,
|
| Rico
|


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting the appearance of a String in a Row [email protected] Excel Worksheet Functions 2 October 3rd 06 02:51 PM
macro unouwanme Excel Discussion (Misc queries) 9 August 31st 06 09:38 PM
Weekly Transaction Processing Ralph Howarth Excel Worksheet Functions 4 January 19th 05 05:37 AM
Read Text File into Excel Using VBA Willie T Excel Discussion (Misc queries) 13 January 8th 05 12:37 AM
counting instances of words in a worksheet cell CJ Excel Discussion (Misc queries) 2 December 22nd 04 02:49 AM


All times are GMT +1. The time now is 04:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"