Macro to cut and paste

CindyA

Board Regular
Joined
May 1, 2002
Messages
102
Good Morning:

I am looking to create a macro to divide a cell (delimit) via a macro versus manually. The file comes in with a cell containing approx. 380 characters. I need to create a column for every 7 characters within that cell and whatever remains after the 371st character would populate the last cell of that row. In addition, the macro should loop until the cell is completely spit up by 7's then continue to the next row until a blank row is encountered. Any ideas (or examples) to get me started?

This is the first message I have ever sent for help, so am not sure of the procedure. Any assistance would be appreciated. Thanks; have a good day.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try this; if problems, just shout:

Sub Macro1()

Dim textstring, textmod As String
Dim column As Integer

Range("a1").Select
textstring = ActiveCell.Formula
Do Until textstring = ""
textmod = textstring
column = 1
Do Until textmod = ""
If (Len(textmod) > 7) Then
ActiveCell.Offset(0, column).Formula = Left(textmod, 7)
textmod = Right(textmod, Len(textmod) - 7)
column = column + 1
Else
ActiveCell.Offset(0, column).Formula = textmod
textmod = ""
End If
Loop
ActiveCell.Offset(1, 0).Select
textstring = ActiveCell.Formula
Loop

End Sub
 
Upvote 0
Added a counter so that after 53 columns of 7 letters the 54th column will be loaded with whatever text is remaining in your string. (Only one line has been changed from the previous code) Again, shout if this doesn't help:

Sub Macro1()

Dim textstring, textmod As String
Dim column As Integer

Range("a1").Select
textstring = ActiveCell.Formula
Do Until textstring = ""
textmod = textstring
column = 1
Do Until textmod = ""
If (Len(textmod) > 7) And column < 54 Then
ActiveCell.Offset(0, column).Formula = Left(textmod, 7)
textmod = Right(textmod, Len(textmod) - 7)
column = column + 1
Else
ActiveCell.Offset(0, column).Formula = textmod
textmod = ""
End If
Loop
ActiveCell.Offset(1, 0).Select
textstring = ActiveCell.Formula
Loop

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,426
Messages
6,119,414
Members
448,895
Latest member
omarahmed1

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