VBA - Remove text between given 2 characters in string

rsulliva

Board Regular
Joined
Sep 13, 2007
Messages
117
I am trying to compare two columns of 1,200 names. The names of some individuals have surnames attached. Ex. (A1: jones-smith,lisa) (B1: jones, lisa a.) Some names have middle initials, spaces, periods and others do not. So Vlookup will not work at this stage. Before breaking the column down using text to columns I would like to run VBA on the column that would I remove all characters including the "-" up to but not including the ",".
I could then break the names down using the text to columns function using a "," and a " " as limits and then recombined and compared without the middle initial using vlookups.

Thanks for your imput.

rsulliva
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Select the column with your names in them, then press Ctrl+H to bring up the Replace dialog box. Type -*, (dash-asterisk-comma) into the "Find what" field, type a comma into the "Replace with" field, then click the "Options>>" button to reveal all the options available and make sure there is no check mark in the "Match entire cell contents" checkbox, then click the "Replace All" button.
 
Upvote 0
Rick, your simple solution works great. I just recorded the actions using a macro and had it run on both columns before any other actions. Thanks.
 
Upvote 0
Rick, your simple solution works great. I just recorded the actions using a macro and had it run on both columns before any other actions. Thanks.
Sorry, I know you said you wanted a VBA solution, but I thought this as a "do-it-once-only" operation, so I gave you a non-VBA solution. Your response sounds like the macro you came up with is being run twice somehow. If so, you don't have to do it that way... here is a one-liner macro that will handle both columns at once.

Code:
Sub RemoveDashToComma()
  Columns("A:B").Replace "-*,", ",", xlPart
End Sub
 
Upvote 0
Sorry, I know you said you wanted a VBA solution, but I thought this as a "do-it-once-only" operation, so I gave you a non-VBA solution. Your response sounds like the macro you came up with is being run twice somehow. If so, you don't have to do it that way... here is a one-liner macro that will handle both columns at once.

Code:
Sub RemoveDashToComma()
  Columns("A:B").Replace "-*,", ",", xlPart
End Sub

How to copy everything between the two 2 characters in sheet2 rows respectively separated by ;
 
Upvote 0
How to copy everything between the two 2 characters in sheet2 rows respectively separated by ;
This is a different question so please start your own thread (and provide some sample data and expected results along with your explanation about what you are trying to do)
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,310
Members
449,152
Latest member
PressEscape

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