Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,069
Default Counting occurences of characters in a cell

Hi,

I've want to be able to return the country in the cells, EG

Luxembourg
London, UK
Miami, FL, USA

I can get this to work using
=IF(ISERROR(FIND(",",P431))=TRUE,P431,TRIM(MID(P43 1,FIND(",",P431)+1,LEN(P431))))

Problem is when i have two ',' i only get Fl, USA where all i want is USA.
I vould possibly use an extra iteration in the function to say if the result
still has a common in then search again, but wanted to know if their is
something in XL that will count the number of ',' in a string?

THanks

John


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,856
Default Counting occurences of characters in a cell

You can use SUBSTITUTE to get rid of the commas, so that (the length
of the original string) minus (the length of the string with the
commas changed to "") will give you the number of commas in the
original.

Hope this helps.

Pete

On Apr 27, 1:54 pm, John wrote:
Hi,

I've want to be able to return the country in the cells, EG

Luxembourg
London, UK
Miami, FL, USA

I can get this to work using
=IF(ISERROR(FIND(",",P431))=TRUE,P431,TRIM(MID(P43 1,FIND(",",P431)+1,LEN(P4*31))))

Problem is when i have two ',' i only get Fl, USA where all i want is USA..
I vould possibly use an extra iteration in the function to say if the result
still has a common in then search again, but wanted to know if their is
something in XL that will count the number of ',' in a string?

THanks

John



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Counting occurences of characters in a cell

=TRIM(RIGHT(A1,LEN(A1)-FIND(CHAR(1),SUBSTITUTE(A1,",",CHAR(1),LEN(A1)
-LEN(SUBSTITUTE(A1,",",""))))))

will return an error if no comma was found.

You could hide it with:

=IF(COUNTIF(A1,"*,*")=0,"",TRIM(RIGHT(A1,LEN(A1)
-FIND(CHAR(1),SUBSTITUTE(A1,",",CHAR(1),LEN(A1)
-LEN(SUBSTITUTE(A1,",","")))))))



John wrote:

Hi,

I've want to be able to return the country in the cells, EG

Luxembourg
London, UK
Miami, FL, USA

I can get this to work using
=IF(ISERROR(FIND(",",P431))=TRUE,P431,TRIM(MID(P43 1,FIND(",",P431)+1,LEN(P431))))

Problem is when i have two ',' i only get Fl, USA where all i want is USA.
I vould possibly use an extra iteration in the function to say if the result
still has a common in then search again, but wanted to know if their is
something in XL that will count the number of ',' in a string?

THanks

John


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,718
Default Counting occurences of characters in a cell

Try this:

=IF(ISERR(FIND(",",A1)),A1,TRIM(RIGHT(A1,LEN(A1)-FIND("^",SUBSTITUTE(A1,",
","^",LEN(A1)-LEN(SUBSTITUTE(A1,",","")))))))


"John" wrote:

Hi,

I've want to be able to return the country in the cells, EG

Luxembourg
London, UK
Miami, FL, USA

I can get this to work using
=IF(ISERROR(FIND(",",P431))=TRUE,P431,TRIM(MID(P43 1,FIND(",",P431)+1,LEN(P431))))

Problem is when i have two ',' i only get Fl, USA where all i want is USA.
I vould possibly use an extra iteration in the function to say if the result
still has a common in then search again, but wanted to know if their is
something in XL that will count the number of ',' in a string?

THanks

John


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 characters in a cell Ram Excel Discussion (Misc queries) 3 July 29th 06 05:04 PM
counting characters inside a cell simonsmith Excel Discussion (Misc queries) 5 July 26th 06 07:30 PM
Counting the occurences riomarde Excel Worksheet Functions 1 March 27th 06 09:00 PM
Counting Occurences Pete Excel Discussion (Misc queries) 7 May 2nd 05 08:28 PM
Counting Characters in a Cell carl Excel Worksheet Functions 2 February 4th 05 04:00 PM


All times are GMT +1. The time now is 05:44 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"