VBA to remove characters until first letter?

Coyotex3

Active Member
Joined
Dec 12, 2021
Messages
496
Office Version
  1. 365
Platform
  1. Windows
Hello guys, This one has me stumped. I'm trying to create a code that will allow me to remove all the characters up to the first letter found.

Here is what the original data looks like on Column A and the Expected Results in Column C

Book3
ABC
11001-OO-BoomOO-Boom
2
31005-AA-BangAA-Bang
4
51009 - AA-Boom BangAA-Boom Bang
6
71002 - EE-BoonEE-Boon
8
90099-II-BeenII-Been
10
111001-OO-BoomOO-Boom
12
131005-AA-BangAA-Bang
14
151009 - AA-Boom BangAA-Boom Bang
16
171002 - EE-BoonEE-Boon
18
190099-II-BeenII-Been
20
211001-OO-BoomOO-Boom
22
231005-AA-BangAA-Bang
24
251009 - AA-Boom BangAA-Boom Bang
26
271002 - EE-BoonEE-Boon
28
290099-II-BeenII-Been
Sheet1


Any ideas on the best way to achieve this?
 
Glad we could help & thanks for the feedback.
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Another option

Excel Formula:
=IF(A1="","",TRIM(REPLACE(A1,1,FIND("-",A1),"")))

With vba:

VBA Code:
Sub macro()
  With Range("C1:C" & Range("A" & Rows.Count).End(xlUp).Row)
    .Value = Evaluate("=IF({1},IF(" & .Offset(, -2).Address & "="""","""",TRIM(REPLACE(" & .Offset(, -2).Address & ",1,FIND(""-""," & .Offset(, -2).Address & "),""""))))")
  End With
End Sub

or

VBA Code:
Sub macro()
  With Range("C1:C" & Range("A" & Rows.Count).End(xlUp).Row)
    .Value = Evaluate(Replace("=IF({1},IF(@="""","""",TRIM(REPLACE(@,1,FIND(""-"",@),""""))))", "@", "" & .Offset(, -2).Address & ""))
  End With
End Sub
 
Upvote 0
Another option

Excel Formula:
=IF(A1="","",TRIM(REPLACE(A1,1,FIND("-",A1),"")))

With vba:

VBA Code:
Sub macro()
  With Range("C1:C" & Range("A" & Rows.Count).End(xlUp).Row)
    .Value = Evaluate("=IF({1},IF(" & .Offset(, -2).Address & "="""","""",TRIM(REPLACE(" & .Offset(, -2).Address & ",1,FIND(""-""," & .Offset(, -2).Address & "),""""))))")
  End With
End Sub

or

VBA Code:
Sub macro()
  With Range("C1:C" & Range("A" & Rows.Count).End(xlUp).Row)
    .Value = Evaluate(Replace("=IF({1},IF(@="""","""",TRIM(REPLACE(@,1,FIND(""-"",@),""""))))", "@", "" & .Offset(, -2).Address & ""))
  End With
End Sub
Thank you! These work as well :biggrin:
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,947
Members
449,095
Latest member
nmaske

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