#1   Report Post  
Posted to microsoft.public.excel.misc
TCF TCF is offline
external usenet poster
 
Posts: 2
Default Counting a Character

I have seen how to count the number of occurances of a particular character,
but is there a way to limit the count to just the left most characters? here
is my example

....PLATE - WELD, TAPPED, .312 - 18

i want to count only the left most "." in this case, it would be 3. If I
use the

=LEN(A1)-LEN(SUBSTITUTE(A1,".","") i get 4 because of the . in the .312.

any help would be appreciated.

thanks

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 896
Default Counting a Character

use this UDF

insert "." as char argument

Function leftchr(char As String, rng As range) As Integer
Dim i As Integer
Dim counter As Integer

For i = 1 To Len(rng.Text)
If Mid(rng.Text, i, 1) = char Then
counter = counter + 1
Else
Exit For
End If
Next i

leftchr = counter

End Function


On 3 Lis, 14:18, TCF wrote:
I have seen how to count the number of occurances of a particular character,
but is there a way to limit the count to just the left most characters? *here
is my example

...PLATE - WELD, TAPPED, .312 - 18

i want to count only the left most "." *in this case, it would be 3. *If I
use the

=LEN(A1)-LEN(SUBSTITUTE(A1,".","") i get 4 because of the . in the .312..

any help would be appreciated.

thanks


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Counting a Character

One way...
=SEARCH(LEFT(TRIM(SUBSTITUTE(A1,"."," ")),1),A1)-1

=substitute() replaces all the dots with spaces.

Then =trim() removes the leading spaces (and trailing and changes multiple
consecutive spaces to a single space.

Then the =left() takes the first character of that trimmed string and looks for
its position in the original string.

And then the formula subtracts 1.

If you could have something like:

.......
(no additional characters), you can add a dummy character to the string and do
the same thing:
=SEARCH(LEFT(TRIM(SUBSTITUTE(A1&"x","."," ")),1),A1&"x")-1



TCF wrote:

I have seen how to count the number of occurances of a particular character,
but is there a way to limit the count to just the left most characters? here
is my example

...PLATE - WELD, TAPPED, .312 - 18

i want to count only the left most "." in this case, it would be 3. If I
use the

=LEN(A1)-LEN(SUBSTITUTE(A1,".","") i get 4 because of the . in the .312.

any help would be appreciated.

thanks


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default Counting a Character

On Tue, 3 Nov 2009 05:18:01 -0800, TCF wrote:

I have seen how to count the number of occurances of a particular character,
but is there a way to limit the count to just the left most characters? here
is my example

...PLATE - WELD, TAPPED, .312 - 18

i want to count only the left most "." in this case, it would be 3. If I
use the

=LEN(A1)-LEN(SUBSTITUTE(A1,".","") i get 4 because of the . in the .312.

any help would be appreciated.

thanks


When you write "left-most" characters, do you mean to start at the first
character? Or at the first left-most instance of the search string?

In other words, what would you want to return, searching for ".", if the string
we

ABC...PLATE - WELD, TAPPED, .312 - 18

0 or 3?

--ron
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default Counting a Character

Well, if "left most" means all but the last one, then just modify the formula
to
=LEN(A1)-LEN(SUBSTITUTE(A1,".","") -1

but if there's some other definition of "left most", then to come up with a
solution we need a clearer definition.


"TCF" wrote:

I have seen how to count the number of occurances of a particular character,
but is there a way to limit the count to just the left most characters? here
is my example

...PLATE - WELD, TAPPED, .312 - 18

i want to count only the left most "." in this case, it would be 3. If I
use the

=LEN(A1)-LEN(SUBSTITUTE(A1,".","") i get 4 because of the . in the .312.

any help would be appreciated.

thanks



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,718
Default Counting a Character

=MIN(IF(ISERROR(FIND(CHAR(ROW(INDIRECT("65:90"))), A1)),"",FIND(CHAR(ROW(INDIRECT("65:90"))),A1)))-1

ctrl+shift+enter, not just enter


"TCF" wrote:

I have seen how to count the number of occurances of a particular character,
but is there a way to limit the count to just the left most characters? here
is my example

...PLATE - WELD, TAPPED, .312 - 18

i want to count only the left most "." in this case, it would be 3. If I
use the

=LEN(A1)-LEN(SUBSTITUTE(A1,".","") i get 4 because of the . in the .312.

any help would be appreciated.

thanks

  #7   Report Post  
Posted to microsoft.public.excel.misc
TCF TCF is offline
external usenet poster
 
Posts: 2
Default Counting a Character

I only want to count the "." on the left side of the string until i hit
another character other than a "."

"JLatham" wrote:

Well, if "left most" means all but the last one, then just modify the formula
to
=LEN(A1)-LEN(SUBSTITUTE(A1,".","") -1

but if there's some other definition of "left most", then to come up with a
solution we need a clearer definition.


"TCF" wrote:

I have seen how to count the number of occurances of a particular character,
but is there a way to limit the count to just the left most characters? here
is my example

...PLATE - WELD, TAPPED, .312 - 18

i want to count only the left most "." in this case, it would be 3. If I
use the

=LEN(A1)-LEN(SUBSTITUTE(A1,".","") i get 4 because of the . in the .312.

any help would be appreciated.

thanks

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 No of character in a string Chandrashekar B Excel Worksheet Functions 1 October 28th 09 06:44 AM
Counting a Specific Character FARAZ QURESHI Excel Discussion (Misc queries) 2 April 27th 09 11:07 AM
Counting # of characters before a certain character NickPro72 Excel Discussion (Misc queries) 4 August 22nd 08 09:17 PM
counting a certain character James Excel Discussion (Misc queries) 3 June 27th 08 09:39 PM
Counting Cells w/ a certain character in them? BradS Excel Discussion (Misc queries) 1 February 28th 07 04:21 PM


All times are GMT +1. The time now is 05:11 PM.

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

About Us

"It's about Microsoft Excel"