VBA Text to Column, consecutive characters

lnpasket

New Member
Joined
Oct 9, 2009
Messages
10
Good Morning All,

Can anyone help me with using VBA to do a text to column with consecutive characters. For example, I have text in a cell which reads "PN-54826 - PCBA, 2711P, 700-1500". I want to separate the text into the following:

Cell B2: PN-54826
Cell C2: PCBA, 2711P, 700-1500

I think the way to go is say to separate at "_-_" but I am not sure how to do that without having everything with a hyphen get separated.

Please help! Thanks in advance.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
How about trying to first do a Search and replace replacing all instance of "space hypen space" with something like a pipe symbol? Then, use the pipe symbol as the delimiter from your Text-to-Columns.
 
Upvote 0
Thanks Mick, I think that will work for me.

Is there an easier way to apply that to a dynamic range without having to index through ever cell?
 
Upvote 0
Is there an easier way to apply that to a dynamic range without having to index through ever cell?
The solution I presented would not require you to loop through each cell.
Its just a Search and Replace on the whole column, then a Text-to-Columns on the whole column.
 
Upvote 0
Try this:-
Code:
Dim Rng As Range, Dn As Range
Set Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
For Each Dn In Rng
    Dn.Offset(, 1).Resize(, 2) = Split(Dn, " - ")
Next Dn
Mick
 
Upvote 0

Forum statistics

Threads
1,224,612
Messages
6,179,890
Members
452,948
Latest member
Dupuhini

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