I have a worksheet that has thousands of rows and only one column (A)
. The cells in column A can be null or up to and over 1000
characters. I need to run a macro that will loop through column A copying it to column B
. If there are any cells that have any text > 60
characters to cut it into blocks of 60
into the next columns.
I have code that breaks text into blocks of 60
but I don't know how to get it to copy anything under 60
, move to next row if null or loop through rows.
Sub x()
Dim cLength As Long, cLoop As Long
cLength = 60
For cLoop = 1 To (Len([A2]) \ cLength) + 1
[A2].Offset(, cLoop).Value = Mid([A2], ((cLoop - 1) * cLength) + 1, cLength)
Next
End Sub
Try this. This should do your job:
Modified your code to make it generic for all rows:
Fastest way to handle it! (Uses no Loops. Processes the entire column in one go)
This uses the inbuilt
Data | Text To Columns
. We are usingFixed Width
to split the data. The below code will handle strings up to1320
characters in length.If you were to do it manually then you would be doing this.