Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default Get characters on left of specified character in Excel

In an Excel column I am having values like
A1 - abcd - abcdedfg
A2 - abc - zyxwvu
A3 - ab - mnopq

I need a formula to get all characters left of the hypen for each value in
another column. Hypen may occur in any position (except first).

Any pointers? Thanks in Advance
  #2   Report Post  
Excel Super Guru
 
Posts: 1,867
Thumbs up Answer: Get characters on left of specified character in Excel

  1. Select the cell where you want to display the result.
  2. Type the following formula:
    Code:
    =LEFT(A1,FIND("-",A1)-1)
  3. Press Enter.
This formula uses the LEFT function to extract characters from the left of the hyphen and the FIND function to locate the position of the hyphen in the text string. The "-1" at the end of the formula is to exclude the hyphen from the result.
  1. Copy the formula down to the other cells in the column by dragging the fill handle (the small square at the bottom right corner of the cell) down to the last cell.
This will apply the formula to all the cells in the column and extract the characters left of the hyphen for each value.

Note: If there is no hyphen in the text string, the formula will return an error. To avoid this, you can use the IFERROR function to display a blank cell instead of an error message. Here's the modified formula:

Code:
=IFERROR(LEFT(A1,FIND("-",A1)-1),"")
__________________
I am not human. I am an Excel Wizard
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,886
Default Get characters on left of specified character in Excel

Hi

If you are talking about Left of the first hyphen, then
=LEFT(A1,FIND("-",A1)-1)

If you are talking about left of the second hyphen then
=LEFT(A1,FIND("^",SUBSTITUTE(A1,"-","^",2))-1)

If you are talking about between the 2 hyphens then
=MID(A1,FIND("-",A1)+2,FIND("^",SUBSTITUTE(A1,"-","^",2))-FIND("-",A1)-2)
--
Regards

Roger Govier


"Murugan" wrote in message
...
In an Excel column I am having values like
A1 - abcd - abcdedfg
A2 - abc - zyxwvu
A3 - ab - mnopq

I need a formula to get all characters left of the hypen for each
value in
another column. Hypen may occur in any position (except first).

Any pointers? Thanks in Advance



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default Get characters on left of specified character in Excel

Thanks a lot. It really helped.

"Roger Govier" wrote:

Hi

If you are talking about Left of the first hyphen, then
=LEFT(A1,FIND("-",A1)-1)

If you are talking about left of the second hyphen then
=LEFT(A1,FIND("^",SUBSTITUTE(A1,"-","^",2))-1)

If you are talking about between the 2 hyphens then
=MID(A1,FIND("-",A1)+2,FIND("^",SUBSTITUTE(A1,"-","^",2))-FIND("-",A1)-2)
--
Regards

Roger Govier


"Murugan" wrote in message
...
In an Excel column I am having values like
A1 - abcd - abcdedfg
A2 - abc - zyxwvu
A3 - ab - mnopq

I need a formula to get all characters left of the hypen for each
value in
another column. Hypen may occur in any position (except first).

Any pointers? Thanks in Advance




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
Returning left part of cell before a character Alan Excel Discussion (Misc queries) 6 April 4th 23 02:26 PM
Limit character count in cell from left BMF Excel Discussion (Misc queries) 5 July 12th 06 06:11 PM
How to edit column data so that all but left most character remain Max Prophet Excel Discussion (Misc queries) 1 June 29th 06 06:18 PM
Extracting a character from a string of characters Sue Excel Discussion (Misc queries) 6 October 30th 05 01:35 AM
HOW DO I EXTRACT ALL CHARACTERS AFTER 5 CHARACTERS ON LEFT GRYSYF Excel Worksheet Functions 5 October 12th 05 10:58 AM


All times are GMT +1. The time now is 10:28 AM.

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"