find chr(45) remove it and text to the right

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
529
if I have some text that looks like: mike turner - manager
I want to correct the text to look like: mike turner
So I Want to detect the - and kill the - and text to the right of it. Any idea's how that would be accomplished?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try

=LEFT(A1,FIND("-",A1)-1)

Assuming there's always a space before the hyphen. If not, remove the -1 at the end.
 
Upvote 0
Here is what I tried. It seems to error at the find statement. Any idea's?
Code:
Dim wks1 As Worksheet
    Set wks1 = Worksheets("names")

Dim cell As Range
Dim clense As String
 
 For Each cell In wks1.Range("a40:a42").Cells
    clense = Left(cell.Value, Find("-", cell.Value) - 1)
    wks1.Range("f" & cell.Row).Value = clense
Next cell
 
Upvote 0
Yes, "Find" isn't available in VBA unless you use WorksheetFunction.Find.

Do you have to use VBA? Either option provided above will work.

If you must, change it to:
Code:
clense = Left(cell.Value, InStr(1, cell.Value, "-") - 1)
 
Upvote 0
Given the text is in A2 and down , in B2 place this formula and copy down

=MID(A2,1,SEARCH("-",A2)-1)

Just another alternative, this way the integrity of original data is perserved (helpful at the time of audit ) :)
 
Upvote 0

Forum statistics

Threads
1,224,523
Messages
6,179,301
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top