Split a word into Two cells

Vikas Kumar

New Member
Joined
Apr 2, 2017
Messages
49
Hi Friends,

I am trying to achieve something like this using VBA:
I have some sentences in first columns as mentioned below and would like to split them into just two cells.


[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 170"]
<colgroup><col width="170"></colgroup><tbody>[TR]
[TD="class: xl65, width: 170"]Text
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 71"]
<colgroup><col width="71"></colgroup><tbody>[TR]
[TD="class: xl65, width: 71"]First Word
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 124"]
<colgroup><col width="124"></colgroup><tbody>[TR]
[TD="class: xl65, width: 124"]Remaining text
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 170"]
<colgroup><col width="170"></colgroup><tbody>[TR]
[TD="class: xl65, width: 170"]Vikas Kumar[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 71"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Vikas
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 124"]
<colgroup><col width="124"></colgroup><tbody>[TR]
[TD="class: xl65, width: 124"]Kumar
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 170"]
<colgroup><col width="170"></colgroup><tbody>[TR]
[TD="class: xl65, width: 170"]Harry Potter
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 71"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Harry [/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 124"]
<colgroup><col width="124"></colgroup><tbody>[TR]
[TD="class: xl65, width: 124"]Potter[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 170"]
<colgroup><col width="170"></colgroup><tbody>[TR]
[TD="class: xl65, width: 170"]Gautam Buddha Nagar
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 71"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Gautam [/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 124"]
<colgroup><col width="124"></colgroup><tbody>[TR]
[TD="class: xl65, width: 124"]Buddha Nagar[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 170"]
<colgroup><col width="170"></colgroup><tbody>[TR]
[TD="class: xl65, width: 170"]This is a Machine[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 71"]
<colgroup><col></colgroup><tbody>[TR]
[TD]This
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 124"]
<colgroup><col width="124"></colgroup><tbody>[TR]
[TD="class: xl65, width: 124"]is a Machine
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 170"]
<colgroup><col width="170"></colgroup><tbody>[TR]
[TD="class: xl65, width: 170"]Where are you going Now
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 71"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Where [/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 124"]
<colgroup><col width="124"></colgroup><tbody>[TR]
[TD="class: xl65, width: 124"]are you going Now
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]


Here I am able to find out column "First Word" & 'Remaining Text" with the help of formula, But unable to get this done by VBA.

Can anyone please help upon this.
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Code:
Public Sub SplitText()

Dim lastRow As Long
Dim thisRow As Long
Dim spacePos As Long

lastRow = Cells(Rows.Count, "A").End(xlUp).Row
For thisRow = 2 To lastRow
    spacePos = InStr(1, Cells(thisRow, 1).Value & " ", " ")
    Cells(thisRow, 2).Value = Left(Cells(thisRow, 1).Value, spacePos - 1)
    Cells(thisRow, 3).Value = Mid(Cells(thisRow, 1).Value, spacePos + 1)
Next thisRow

End Sub

WBD
 
Upvote 0
Code:
Public Sub SplitText()

Dim lastRow As Long
Dim thisRow As Long
Dim spacePos As Long

lastRow = Cells(Rows.Count, "A").End(xlUp).Row
For thisRow = 2 To lastRow
    spacePos = InStr(1, Cells(thisRow, 1).Value & " ", " ")
    Cells(thisRow, 2).Value = Left(Cells(thisRow, 1).Value, spacePos - 1)
    Cells(thisRow, 3).Value = Mid(Cells(thisRow, 1).Value, spacePos + 1)
Next thisRow

End Sub

WBD

Wow wideboydixon!!!!! This did the task.

Thanks for quick reply and the solution.:)
 
Upvote 0

Forum statistics

Threads
1,223,721
Messages
6,174,097
Members
452,542
Latest member
Bricklin

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