Splitting a cell based on character count, with a header for each line

ccwalker

New Member
Joined
Feb 6, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi everyone, I am looking for some help I am attempting to split the following text into multiple rows based on a 70 character count. and also give each line that it splits into the adjacent rows number. Below is an example line that I am attempting to split. I have 500 or so lines to do. There is also a code I have partially working and what that code outputs. There are several things I could use some help with. ( I got this code from this FORUM on another thread and members user name is Scott Huish, so by no means am a good at VBA.) Any help would be appreciated.
1) The code Run-Time error '1004' every time and will only work to line 72 in my spreadsheet
2) I don't know how to get the code to add the adjacent row # to every line it splits into.
3) Not as big of a deal but some of the lines split oddly see "DOES NOT
COMPLY"
4) Also if it could convert everything into capital letter that would be a bonus.

10080920hsg-std-15063584002-rev10 under construction Design and format changes, BF12, Keystone Prince, **”-222-789-805-#, CL125, Lugged, Butterfly, Lever, , Gear for 8" and larger, SSG Number(s) 15.063. 501, 502, 504, 579, Special Designation(s): # = 001 for lever & 002 for gear operator. Valve shall have lockable lever and shall be open position during install. Valve has molded in O-rings for flange to flange connection. No other gasket required for sealing
DOES NOT COMPLY WITH LEAD FREE REQUIREMENTS FOR POTABLE WATER, Materials: Body/Bonnet: CI, Seats: Molded-in EPDM, Ball/Disc/Plug/Etc: 304 SS, Stem: 416 SS, Body Bolts & Nuts: , Gland Bolts & Nuts: , Belleville Washers: , Packing: , Body/Bonnet Seals: , Other: Bushing: Acetal, Notes:
hsg-std-15063584002-rev10 under construction Design and format
changes, BF12, Keystone Prince, **”-222-789-805-#, CL125, Lugged,
Butterfly, Lever, , Gear for 8" and larger, SSG Number(s) 15.063. 501,
502, 504, 579, Special Designation(s): # = 001 for lever & 002 for
gear operator. Valve shall have lockable lever and shall be open
position during install. Valve has molded in O-rings for flange to
flange connection. No other gasket required for sealing
DOES NOT
COMPLY WITH LEAD FREE REQUIREMENTS FOR POTABLE WATER, Materials:
Body/Bonnet: CI, Seats: Molded-in EPDM, Ball/Disc/Plug/Etc: 304 SS,
Stem: 416 SS, Body Bolts & Nuts: , Gland Bolts & Nuts: , Belleville
Washers: , Packing: , Body/Bonnet Seals: , Other: Bushing: Acetal,
Notes:


Sub splitup70()
Dim c As Range, z As String, tmp As String, j As Long, k As Integer
k = -1
For Each c In Range("B1", Range("B65536").End(xlUp))
z = Trim(c)
Do
tmp = Trim(Left(z, 70))
j = 70
If Right(tmp, 1) <> " " And (Mid(z, 71, 1) <> " " And Len(z) > 70) And Right(tmp, 1) <> "." And Right(tmp, 1) <> "," Then j = InStrRev(tmp, " ")
tmp = Left(tmp, j)
If tmp <> "" Then Range("D65536").End(xlUp).Offset(1 + k, 0) = tmp
k = 0
z = Trim(Mid(z, j + 1))
Loop Until tmp = ""
k = 1
Next
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Here is a link to the original thread I found.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

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