Hello All;
I have a macro requirement were the macro reads a text in a cell; copies the first 30 characters; inserts the test into a new row. The macro contiues were it left off reading the next 30 characetrs and inserting a 2nd row pasting the text. This process continues until there is no more text to read in the cell.
Inaddition the macro should observe the following restrictions:
1) The macro should not slice into words...defauts to the beginning of the word were the 30 character mark is.
2) Inserts new rows instead of pasting. This is to prevent overwriting data below the cells were the souce cell is.
Sample output: Applying the macro to the first paragraph above it should look like this:
<TABLE style="WIDTH: 195pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=260><COLGROUP><COL style="WIDTH: 195pt; mso-width-source: userset; mso-width-alt: 9508" width=260><TBODY><TR style="HEIGHT: 165.75pt" height=221><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 195pt; HEIGHT: 165.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl63 height=221 width=260>I have a macro requirement
were the macro reads a text
in a cell; copies the first
50 characters; inserts
the test into a new row. The
macro contiues were it left
off reading the next 50
characetrs and inserting a
2nd row pasting the text.
This process continues until
there is no more text to read
in the
cell.</TD></TR></TBODY></TABLE>
Mr. Beaucaire solution to post "counting characters to 50 and adding to new line" July 5, 2009 does a great job however it slices into words and does not insert new rows.
Thank You All!
jaime
Mr. Beaucaire solution "counting characters to 50 and adding to new line"
Sub Split50()
Dim MyVal As String, i As Long
MyVal = Range("A1")
Do
i = i + 1
If Len(MyVal) > 50 Then
Range("A" & i) = Left(MyVal, 50)
MyVal = Right(MyVal, Len(MyVal) - 50)
Else
Range("A" & i) = MyVal
Exit Do
End If
Loop
End Sub
I have a macro requirement were the macro reads a text in a cell; copies the first 30 characters; inserts the test into a new row. The macro contiues were it left off reading the next 30 characetrs and inserting a 2nd row pasting the text. This process continues until there is no more text to read in the cell.
Inaddition the macro should observe the following restrictions:
1) The macro should not slice into words...defauts to the beginning of the word were the 30 character mark is.
2) Inserts new rows instead of pasting. This is to prevent overwriting data below the cells were the souce cell is.
Sample output: Applying the macro to the first paragraph above it should look like this:
<TABLE style="WIDTH: 195pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=260><COLGROUP><COL style="WIDTH: 195pt; mso-width-source: userset; mso-width-alt: 9508" width=260><TBODY><TR style="HEIGHT: 165.75pt" height=221><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 195pt; HEIGHT: 165.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl63 height=221 width=260>I have a macro requirement
were the macro reads a text
in a cell; copies the first
50 characters; inserts
the test into a new row. The
macro contiues were it left
off reading the next 50
characetrs and inserting a
2nd row pasting the text.
This process continues until
there is no more text to read
in the
cell.</TD></TR></TBODY></TABLE>
Mr. Beaucaire solution to post "counting characters to 50 and adding to new line" July 5, 2009 does a great job however it slices into words and does not insert new rows.
Thank You All!
jaime
Mr. Beaucaire solution "counting characters to 50 and adding to new line"
Sub Split50()
Dim MyVal As String, i As Long
MyVal = Range("A1")
Do
i = i + 1
If Len(MyVal) > 50 Then
Range("A" & i) = Left(MyVal, 50)
MyVal = Right(MyVal, Len(MyVal) - 50)
Else
Range("A" & i) = MyVal
Exit Do
End If
Loop
End Sub