Dividing long string in 1 cell to 2 cells

newvbie

Board Regular
Joined
Mar 18, 2006
Messages
69
Hi there. I got 90,000 records in which contents may exceed the required length for each cell. Here is the example:

A2: UNIT A 14/F JCG INTERNATIONAL BUILDING 16 MONGKOK ROAD HONG KONG

I tried the following vba to break the cell into two but the word will be truncated.

For k = 2 To 95000
leng = Len(Range("A" & k))
If leng > 30 Then //if the lengh > 30 characters
Range("B" & k).Value = Right(Range("A" & k), 20)
Range("A" & k).Value = Left(Range("A" & k), leng - 20)
End If
Next

How can capture (by simple vba script) the required length of cell A2 with the space at the end and transfer the remaining part to cell B2 to the following effect?

A2: UNIT A 14/F JCG INTERNATIONAL
B2: BUILDING 16 MONGKOK ROAD HONG KONG

Thanks.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,224,567
Messages
6,179,571
Members
452,927
Latest member
whitfieldcraig

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