Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default How do I find a dash in a cell with numbers in it in excel.

I'm working in Excel 2003 with zip codes, people supply them in 5 digit, 9
digit or 9 digit with dash. I used
=IF(FIND("-",(A14))0,LEFT(A14,FIND("-",(A14))-1),A14) to get the 5 digit but
if there is no dash it will value out. Does anyone know how I can test the
cell for the dash first.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,240
Default How do I find a dash in a cell with numbers in it in excel.

Finky wrote:
I'm working in Excel 2003 with zip codes, people supply them in 5 digit, 9
digit or 9 digit with dash. I used
=IF(FIND("-",(A14))0,LEFT(A14,FIND("-",(A14))-1),A14) to get the 5 digit but
if there is no dash it will value out. Does anyone know how I can test the
cell for the dash first.



=IF(ISERROR(FIND("-",A14)), no dash found , dash found )
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default How do I find a dash in a cell with numbers in it in excel.

If you only want the first 5 digits and they are always before the dash, why
not just pull them out directly...

=LEFT(A14,5)

If you want to use this across cells that might be blank...

=IF(A14="","",LEFT(A14,5))

--
Rick (MVP - Excel)


"Finky" wrote in message
...
I'm working in Excel 2003 with zip codes, people supply them in 5 digit, 9
digit or 9 digit with dash. I used
=IF(FIND("-",(A14))0,LEFT(A14,FIND("-",(A14))-1),A14) to get the 5 digit
but
if there is no dash it will value out. Does anyone know how I can test the
cell for the dash first.


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default How do I find a dash in a cell with numbers in it in excel.

The problem with this is many zip codes begin with zeros, and, with a varying
amount of digits I couldn't force the zeros, but I appreciate your help.

"Rick Rothstein" wrote:

If you only want the first 5 digits and they are always before the dash, why
not just pull them out directly...

=LEFT(A14,5)

If you want to use this across cells that might be blank...

=IF(A14="","",LEFT(A14,5))

--
Rick (MVP - Excel)


"Finky" wrote in message
...
I'm working in Excel 2003 with zip codes, people supply them in 5 digit, 9
digit or 9 digit with dash. I used
=IF(FIND("-",(A14))0,LEFT(A14,FIND("-",(A14))-1),A14) to get the 5 digit
but
if there is no dash it will value out. Does anyone know how I can test the
cell for the dash first.



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default How do I find a dash in a cell with numbers in it in excel.

How about showing us *several* representative samples of your data and tell
us what results you expect.

--
Biff
Microsoft Excel MVP


"Finky" wrote in message
...
The problem with this is many zip codes begin with zeros, and, with a
varying
amount of digits I couldn't force the zeros, but I appreciate your help.

"Rick Rothstein" wrote:

If you only want the first 5 digits and they are always before the dash,
why
not just pull them out directly...

=LEFT(A14,5)

If you want to use this across cells that might be blank...

=IF(A14="","",LEFT(A14,5))

--
Rick (MVP - Excel)


"Finky" wrote in message
...
I'm working in Excel 2003 with zip codes, people supply them in 5
digit, 9
digit or 9 digit with dash. I used
=IF(FIND("-",(A14))0,LEFT(A14,FIND("-",(A14))-1),A14) to get the 5
digit
but
if there is no dash it will value out. Does anyone know how I can test
the
cell for the dash first.







  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,059
Default How do I find a dash in a cell with numbers in it in excel.

"Finky" wrote:
The problem with this is many zip codes begin with zeros, and, with a
varying
amount of digits I couldn't force the zeros, but I appreciate your help.


It sounds to me like you are treating some zip codes as numbers (those
without dashes) and some zip codes as text (those with dashes).

First, let me say that I think that is a bad idea in principle. More about
that below.

But if my assumption is correct, I think the following should work in both
cases:

=if(len(A1)<=5, text(A1,"00000"), left(A1,5))

Note that the result is always text.

Since some zip codes __must__ be treated as text (those with dashes),
__all__ zip codes should be treated as text. It is a good idea for cell
values to be homogenous. This makes it easier to manipulate them in other
formulas, as you see here.

(One exception: the null string ("") should be permissible in cells that
normally have numbers. Ideally, Excel would treat the null string as zero
in numeric expression, just as it treats empty cells. But Excel does not
<sigh.)

If you are importing the data, usually you can tell the Import Wizard to
treat the column with zip codes as text.

If you are entering the data manually, prefix the zip code with a single
quote (aka apostrophe). Alternatively, set the cell format to Text before
entering data.


----- original message -----

"Finky" wrote in message
...
The problem with this is many zip codes begin with zeros, and, with a
varying
amount of digits I couldn't force the zeros, but I appreciate your help.

"Rick Rothstein" wrote:

If you only want the first 5 digits and they are always before the dash,
why
not just pull them out directly...

=LEFT(A14,5)

If you want to use this across cells that might be blank...

=IF(A14="","",LEFT(A14,5))

--
Rick (MVP - Excel)


"Finky" wrote in message
...
I'm working in Excel 2003 with zip codes, people supply them in 5
digit, 9
digit or 9 digit with dash. I used
=IF(FIND("-",(A14))0,LEFT(A14,FIND("-",(A14))-1),A14) to get the 5
digit
but
if there is no dash it will value out. Does anyone know how I can test
the
cell for the dash first.




  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,651
Default How do I find a dash in a cell with numbers in it in excel.

You can force the zeroes with a text function if your cell contains a
number, or use the LEN function and pad out with zeroes (or pad out with
zeroes anyway & use the RIGHT function) if you have text.
--
David Biddulph

"Finky" wrote in message
...
The problem with this is many zip codes begin with zeros, and, with a
varying
amount of digits I couldn't force the zeros, but I appreciate your help.

"Rick Rothstein" wrote:

If you only want the first 5 digits and they are always before the dash,
why
not just pull them out directly...

=LEFT(A14,5)

If you want to use this across cells that might be blank...

=IF(A14="","",LEFT(A14,5))

--
Rick (MVP - Excel)


"Finky" wrote in message
...
I'm working in Excel 2003 with zip codes, people supply them in 5
digit, 9
digit or 9 digit with dash. I used
=IF(FIND("-",(A14))0,LEFT(A14,FIND("-",(A14))-1),A14) to get the 5
digit
but
if there is no dash it will value out. Does anyone know how I can test
the
cell for the dash first.





  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default How do I find a dash in a cell with numbers in it in excel.

On Thu, 13 Aug 2009 13:31:02 -0700, Finky
wrote:

I'm working in Excel 2003 with zip codes, people supply them in 5 digit, 9
digit or 9 digit with dash. I used
=IF(FIND("-",(A14))0,LEFT(A14,FIND("-",(A14))-1),A14) to get the 5 digit but
if there is no dash it will value out. Does anyone know how I can test the
cell for the dash first.


It looks like you are trying to obtain the first five digits of zip codes,
entered in various formats. Try this which should retain leading zeros:

=LEFT(TEXT(SUBSTITUTE(A1,"-",""),"[<100000]00000;00000-0000"),5)

Of course, this does not test to ensure your data is in one of the three
acceptable formats.

--ron
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default How do I find a dash in a cell with numbers in it in excel.

The problem with this is many zip codes begin with zeros, and, with a
varying
amount of digits I couldn't force the zeros


So what does a zip code like 01234 look like in your worksheet, this 1234? I
agree with JoeU2004's comments about making your data all text to begin
with. However, for what I think you are describing, this formula should work
with your current setup...

=TEXT(LEFT(A1,FIND("-",A1&"-")-1),"00000")

If you ever switch your data to all text so that the leading zeroes will be
displayed, then you can use the simpler (and more efficient) formula I
posted originally.

--
Rick (MVP - Excel)


"Finky" wrote in message
...
The problem with this is many zip codes begin with zeros, and, with a
varying
amount of digits I couldn't force the zeros, but I appreciate your help.

"Rick Rothstein" wrote:

If you only want the first 5 digits and they are always before the dash,
why
not just pull them out directly...

=LEFT(A14,5)

If you want to use this across cells that might be blank...

=IF(A14="","",LEFT(A14,5))

--
Rick (MVP - Excel)


"Finky" wrote in message
...
I'm working in Excel 2003 with zip codes, people supply them in 5
digit, 9
digit or 9 digit with dash. I used
=IF(FIND("-",(A14))0,LEFT(A14,FIND("-",(A14))-1),A14) to get the 5
digit
but
if there is no dash it will value out. Does anyone know how I can test
the
cell for the dash first.




  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,059
Default How do I find a dash in a cell with numbers in it in excel.

Errata....

I wrote:
=if(len(A1)<=5, text(A1,"00000"), left(A1,5))


Oops: I made an inexplicable assumption that is incorrect.

Rick's 2nd formula is the correct one to use. To reiterate:

=TEXT(LEFT(A1, FIND("-", A1&"-")-1), "00000")


----- original message -----

"JoeU2004" wrote in message
...
"Finky" wrote:
The problem with this is many zip codes begin with zeros, and, with a
varying
amount of digits I couldn't force the zeros, but I appreciate your help.


It sounds to me like you are treating some zip codes as numbers (those
without dashes) and some zip codes as text (those with dashes).

First, let me say that I think that is a bad idea in principle. More
about that below.

But if my assumption is correct, I think the following should work in both
cases:

=if(len(A1)<=5, text(A1,"00000"), left(A1,5))

Note that the result is always text.

Since some zip codes __must__ be treated as text (those with dashes),
__all__ zip codes should be treated as text. It is a good idea for cell
values to be homogenous. This makes it easier to manipulate them in other
formulas, as you see here.

(One exception: the null string ("") should be permissible in cells that
normally have numbers. Ideally, Excel would treat the null string as zero
in numeric expression, just as it treats empty cells. But Excel does not
<sigh.)

If you are importing the data, usually you can tell the Import Wizard to
treat the column with zip codes as text.

If you are entering the data manually, prefix the zip code with a single
quote (aka apostrophe). Alternatively, set the cell format to Text before
entering data.


----- original message -----

"Finky" wrote in message
...
The problem with this is many zip codes begin with zeros, and, with a
varying
amount of digits I couldn't force the zeros, but I appreciate your help.

"Rick Rothstein" wrote:

If you only want the first 5 digits and they are always before the dash,
why
not just pull them out directly...

=LEFT(A14,5)

If you want to use this across cells that might be blank...

=IF(A14="","",LEFT(A14,5))

--
Rick (MVP - Excel)


"Finky" wrote in message
...
I'm working in Excel 2003 with zip codes, people supply them in 5
digit, 9
digit or 9 digit with dash. I used
=IF(FIND("-",(A14))0,LEFT(A14,FIND("-",(A14))-1),A14) to get the 5
digit
but
if there is no dash it will value out. Does anyone know how I can test
the
cell for the dash first.




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
Help! How do you get excel to find the x(changes daily, marked in a cell from another formula) highest numbers in a group of numbers and sum them up? C-Man23 Excel Worksheet Functions 3 January 19th 06 09:52 AM
Help! How do you get excel to find the x(changes daily, marked in a cell from another formula) highest numbers in a group of numbers and sum them up? C-Man23 Excel Worksheet Functions 1 January 9th 06 01:23 PM
understanding dash dash in a excel formula ldebner Excel Worksheet Functions 2 October 31st 05 01:47 PM
Find an empty cell and put a dash in it? markexcel Excel Worksheet Functions 5 October 12th 05 03:47 PM
Count comma separated numbers, numbers in a range with dash, not t Mahendra Excel Discussion (Misc queries) 0 August 8th 05 05:56 PM


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