Need Macro for splitting sentence

mavericky99

New Member
Joined
Jul 22, 2015
Messages
9
Hi,

I have a requirement to prepare a macro to split a characters in a cell after 256 characters and transfer it to the next cell.

example : (considering that I split for every 1 character)

Input

cell 1 cell 2 cell 3

ABC

Output :

cell 1 cell 2 cell 3

A B C


Similar to the above method the data must be split only into 3 cells i.e.., that if there are more than 256*3 characters.
First cell must have 256 characters, second cell must have 256 characters and 3rd cell must have rest of the characters. (If less than 256*3 it must leave the rest of the cells empty).

Please help!

Thanks,
Anand.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Even though I suspect this might be homework.
Assuming the string is in cell A1 and the three destination cells are A2:A4
Code:
Sub t()
Dim rng As Range
Set rng = Range("A1")
Range("A2") = Left(rng, 256)
Range("A3") = Mid(rng, 257, 256)
Range("A4") = Mid(rng, 513, Len(rng.Value) - 512)
End Sub
 
Upvote 0
Even though I suspect this might be homework.
Assuming the string is in cell A1 and the three destination cells are A2:A4
Code:
Sub t()
Dim rng As Range
Set rng = Range("A1")
Range("A2") = Left(rng, 256)
Range("A3") = Mid(rng, 257, 256)
Range("A4") = Mid(rng, 513, Len(rng.Value) - 512)
End Sub

Hi JLGWiz,

Unfortunately, I have to say your guess is wrong. This belongs to my office work. :) . I am very bad at writing macros. :(

I have tried running the code and it says Run time Error '5'.

Also, I want to replace the first cell data as well and not keep it after running the macro.

Example :

Cell1 Cell2 Cell3

ABC

After running macro it must be

Cell1 Cell2 Cell3

A B C

Can you please help?

Thanks,
Anand.
 
Upvote 0

Forum statistics

Threads
1,215,560
Messages
6,125,523
Members
449,236
Latest member
Afua

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