PC Review


Reply
Thread Tools Rate Thread

count no. of times a text appears in a sheet.

 
 
=?Utf-8?B?S2hhbGVlbA==?=
Guest
Posts: n/a
 
      6th Jul 2007
i need to count the number of times a particular text string appears in a
sheet, and store that number in a variable.

the problem is....the text i want to search is a part of a larger text string.
eg:
say i want to count the number of times the word "joe" appears on a sheet...

the sheet contains data like
"joe is a good boy"
"i asked joe"
"compjoenis"

i should be able to write a command like :

N = {whatever solution you give}
[i should get a answer as 3]

so that i can use the variable "n" in my further calculations.

i hope i have conveyed my doubt....

any help on this is really appreciated.
thanks in advance.

Regards
Khaleel



 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZSBI?=
Guest
Posts: n/a
 
      6th Jul 2007
Khaleel,

Try this. It's worksheet code so right click the sheet tab and paste it in:-

Sub thehuntforjoe()
Dim mtRange As Range
Set myrange = Range("a1:c100") '<Change to suit
For Each c In myrange
If InStr(1, c.Value, "joe") > 0 Then
Count = Count + 1
End If
Next c
MsgBox ("There are " & Count & " occuerences of joe in the range")
End Sub

Mike

"Khaleel" wrote:

> i need to count the number of times a particular text string appears in a
> sheet, and store that number in a variable.
>
> the problem is....the text i want to search is a part of a larger text string.
> eg:
> say i want to count the number of times the word "joe" appears on a sheet...
>
> the sheet contains data like
> "joe is a good boy"
> "i asked joe"
> "compjoenis"
>
> i should be able to write a command like :
>
> N = {whatever solution you give}
> [i should get a answer as 3]
>
> so that i can use the variable "n" in my further calculations.
>
> i hope i have conveyed my doubt....
>
> any help on this is really appreciated.
> thanks in advance.
>
> Regards
> Khaleel
>
>
>

 
Reply With Quote
 
=?Utf-8?B?S2hhbGVlbA==?=
Guest
Posts: n/a
 
      6th Jul 2007
correct me if i m wrong.....
if this is a worksheet code........
i m going to use this on a large number of diffrent files!!
will it work??

i have no formal training in VBA.....
what i do is write code in modules, and save it as .xla and it seems to work
across files..

"Mike H" wrote:

> Khaleel,
>
> Try this. It's worksheet code so right click the sheet tab and paste it in:-
>
> Sub thehuntforjoe()
> Dim mtRange As Range
> Set myrange = Range("a1:c100") '<Change to suit
> For Each c In myrange
> If InStr(1, c.Value, "joe") > 0 Then
> Count = Count + 1
> End If
> Next c
> MsgBox ("There are " & Count & " occuerences of joe in the range")
> End Sub
>
> Mike
>
> "Khaleel" wrote:
>
> > i need to count the number of times a particular text string appears in a
> > sheet, and store that number in a variable.
> >
> > the problem is....the text i want to search is a part of a larger text string.
> > eg:
> > say i want to count the number of times the word "joe" appears on a sheet...
> >
> > the sheet contains data like
> > "joe is a good boy"
> > "i asked joe"
> > "compjoenis"
> >
> > i should be able to write a command like :
> >
> > N = {whatever solution you give}
> > [i should get a answer as 3]
> >
> > so that i can use the variable "n" in my further calculations.
> >
> > i hope i have conveyed my doubt....
> >
> > any help on this is really appreciated.
> > thanks in advance.
> >
> > Regards
> > Khaleel
> >
> >
> >

 
Reply With Quote
 
=?Utf-8?B?S2hhbGVlbA==?=
Guest
Posts: n/a
 
      6th Jul 2007
correct me if i m wrong.....
if this is a worksheet code........
i m going to use this on a large number of diffrent files!!
will it work??

i have no formal training in VBA.....
what i do is write code in modules, and save it as .xla and it seems to work
across files..


Also i just came across "countif" function!!
which has a format like....

=COUNTIF(A1:C100,"Joe")
i can use this on a cell in the worksheet, and then pick this value in my
code!!!(i hope this works)

BUT here too the problem is , it counts only if the entire content of the
cell is just "Joe"
it wont count if JOE is a part of larger string...
any idea, if i can use wildcards (*) inside countif function??

anyother workaround would also help.
thanks


"Mike H" wrote:

> Khaleel,
>
> Try this. It's worksheet code so right click the sheet tab and paste it in:-
>
> Sub thehuntforjoe()
> Dim mtRange As Range
> Set myrange = Range("a1:c100") '<Change to suit
> For Each c In myrange
> If InStr(1, c.Value, "joe") > 0 Then
> Count = Count + 1
> End If
> Next c
> MsgBox ("There are " & Count & " occuerences of joe in the range")
> End Sub
>
> Mike
>
> "Khaleel" wrote:
>
> > i need to count the number of times a particular text string appears in a
> > sheet, and store that number in a variable.
> >
> > the problem is....the text i want to search is a part of a larger text string.
> > eg:
> > say i want to count the number of times the word "joe" appears on a sheet...
> >
> > the sheet contains data like
> > "joe is a good boy"
> > "i asked joe"
> > "compjoenis"
> >
> > i should be able to write a command like :
> >
> > N = {whatever solution you give}
> > [i should get a answer as 3]
> >
> > so that i can use the variable "n" in my further calculations.
> >
> > i hope i have conveyed my doubt....
> >
> > any help on this is really appreciated.
> > thanks in advance.
> >
> > Regards
> > Khaleel
> >
> >
> >

 
Reply With Quote
 
=?Utf-8?B?S2hhbGVlbA==?=
Guest
Posts: n/a
 
      6th Jul 2007
HEY I GOT IT MIKE,
Thanks

"Khaleel" wrote:

> correct me if i m wrong.....
> if this is a worksheet code........
> i m going to use this on a large number of diffrent files!!
> will it work??
>
> i have no formal training in VBA.....
> what i do is write code in modules, and save it as .xla and it seems to work
> across files..
>
>
> Also i just came across "countif" function!!
> which has a format like....
>
> =COUNTIF(A1:C100,"Joe")
> i can use this on a cell in the worksheet, and then pick this value in my
> code!!!(i hope this works)
>
> BUT here too the problem is , it counts only if the entire content of the
> cell is just "Joe"
> it wont count if JOE is a part of larger string...
> any idea, if i can use wildcards (*) inside countif function??
>
> anyother workaround would also help.
> thanks
>
>
> "Mike H" wrote:
>
> > Khaleel,
> >
> > Try this. It's worksheet code so right click the sheet tab and paste it in:-
> >
> > Sub thehuntforjoe()
> > Dim mtRange As Range
> > Set myrange = Range("a1:c100") '<Change to suit
> > For Each c In myrange
> > If InStr(1, c.Value, "joe") > 0 Then
> > Count = Count + 1
> > End If
> > Next c
> > MsgBox ("There are " & Count & " occuerences of joe in the range")
> > End Sub
> >
> > Mike
> >
> > "Khaleel" wrote:
> >
> > > i need to count the number of times a particular text string appears in a
> > > sheet, and store that number in a variable.
> > >
> > > the problem is....the text i want to search is a part of a larger text string.
> > > eg:
> > > say i want to count the number of times the word "joe" appears on a sheet...
> > >
> > > the sheet contains data like
> > > "joe is a good boy"
> > > "i asked joe"
> > > "compjoenis"
> > >
> > > i should be able to write a command like :
> > >
> > > N = {whatever solution you give}
> > > [i should get a answer as 3]
> > >
> > > so that i can use the variable "n" in my further calculations.
> > >
> > > i hope i have conveyed my doubt....
> > >
> > > any help on this is really appreciated.
> > > thanks in advance.
> > >
> > > Regards
> > > Khaleel
> > >
> > >
> > >

 
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
Count number times text appears in string nc Microsoft Excel Misc 1 5th May 2010 02:53 PM
count the amount of times a two letters appears in text string Sam Microsoft Excel Misc 6 22nd May 2009 05:18 AM
count the amount of times a two letters appears in text string Sam Microsoft Excel Misc 0 22nd May 2009 04:12 AM
Count the number of times specific text appears in a column Nannie Microsoft Excel Worksheet Functions 6 27th Aug 2008 07:09 PM
count number of times text appears =?Utf-8?B?TU1jUQ==?= Microsoft Excel Misc 3 9th Feb 2007 07:33 PM


Features
 

Advertising
 

Newsgroups
 


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