![]() |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 03:41 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com