How best to remove data from cells

Sundance_Kid

Board Regular
Joined
Sep 2, 2017
Messages
129
Office Version
  1. 365
Platform
  1. Windows
Hi there, I have a list of names and numbers all in one with a hyphen separating the name and number. I want to remove the number & hyphen.

Bill Clinton - 1234
Joe Biden - 5678

So, basically all the above appears in a cell & I want to just see it appear like :

Bill Clinton
Joe Biden

Can someone advise on how best to formulate it to remove the hyphen & number from the excel cell.

Thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Assuming your data is in column A starting in row 2, try:
VBA Code:
Sub RemoveData()
    Application.ScreenUpdating = False
    Dim rng As Range
    For Each rng In Range("A2", Range("A" & Rows.Count).End(xlUp))
        rng = Split(rng, " -")(0)
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
If you want a macro, another option is
VBA Code:
Sub sundance()
   With Range("A2", Range("A" & Rows.count).End(xlUp))
      .Value = Evaluate(Replace("trim(left(@,find(""-"",@&""-"")-1))", "@", .Address))
   End With
End Sub
 
Upvote 0
Thank you all, I want to avoid trying to use/set-up a macro, so the formula option is probably the best. However, the version of Office the Textbefore option but I am due an upgrade of my office version in the next couple of days, so I will try then.
Thanks
 
Upvote 0
If you don't have the textbefore function yet, you can use
Excel Formula:
=TRIM(LEFT(A2,FIND("-",A2&"-")-1))
 
Upvote 0

Forum statistics

Threads
1,215,168
Messages
6,123,408
Members
449,098
Latest member
ArturS75

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