VBA - text string to multiple cells

omnivl

Board Regular
Joined
Aug 25, 2014
Messages
53
Have searched this for the most part of today and have not found this specific question....may be a first :)

I have a text string in VBA that i insert in a cell on a worksheet, now this string can vary in length and may go across two pages. What i would like to do is
split this string into two cells if it goes over one page. There are pictures in the skip this row area so i cannot simply merge all rows....

For example:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Start of text string in this cell
[/TD]
[/TR]
[TR]
[TD]Skip this row
[/TD]
[/TR]
[TR]
[TD]Skip this row
[/TD]
[/TR]
[TR]
[TD]Skip this row
[/TD]
[/TR]
[TR]
[TD]Continue text string in this cell
[/TD]
[/TR]
</tbody>[/TABLE]
 

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.
try this on a copy of your file,

adjust the ranges A1 and A5 as needed

Code:
Sub Split_me()

x = Len([A1])
y = WorksheetFunction.Find(" ", [A1], x / 2)

[A5] = Mid([A1], y + 1, x)
[A1] = Mid([A1], 1, y - 1)

End Sub

hth,
Ross
 
Upvote 0
Thanks rpaulson

This is close to what im after, the problem with this if there is only two words they will be split across two pages when they could have fitted in the first merged area
i have started a new thread to better explain :)
 
Upvote 0

Forum statistics

Threads
1,223,785
Messages
6,174,539
Members
452,571
Latest member
MarExcelTips

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