How to split a string of text!

peteroldfield1971

New Member
Joined
Apr 27, 2005
Messages
48
Hi,

Can any one help me do the following?

In column A I have a string of text eg:

1. in my life - the beatles

In cell B1 i want "1", in cell C1 "2in my life" and in D1 "the beatles"

I would like to run this with a button if possible to repeat the macro through rows 1 to 180.

Any one help?

Many thanks.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Are there special markers indicating where to stop grabing the string?
ie: number followed by a "." Then Title followed by "-". Remaining is the band name?
 
Upvote 0
I'll assume that those are the delimited points. If so something like this would work

Public Sub whatever()
Dim intPeriodPos As Integer
Dim intHyphenPos As Integer
Dim currRow As Long
Dim currString As String

currRow = 1
For I = 0 To 180 'how ever many

currString = Range("A" & currRow)
intPeriodPos = InStr(currString, ".")
intHyphenPos = InStr(currString, "-")

Range("B" & currRow).Value = Left(currString, intPeriodPos)
Range("C" & currRow).Value = Mid(currString, intPeriodPos + 2, intHyphenPos - intPeriodPos - 2)
Range("D" & currRow).Value = Right(currString, Len(currString) - intHyphenPos - 1)
Next

End Sub
 
Upvote 0
Sharkie21 beat me to the post. I had a similar idea;

Code:
Private Sub CommandButton1_Click()
Dim myText1 As Variant
Dim myText2 As Variant

Dim delimiter1 As String
Dim delimiter2 As String

delimiter1 = ". "
delimiter2 = " - "

For i = 1 To 16
    myText1 = Split(Cells(i, 1).Text, delimiter1)
    Cells(i, 1) = myText1(0)
    myText2 = Split(myText1(1), delimiter2)
    Cells(i, 2) = myText2(0)
    Cells(i, 3) = myText2(1)
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,433
Members
448,897
Latest member
ksjohnson1970

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