Hi there. I've been trying to format a cell which was made from a screen scrape from an oracledb. Unfortunately it took the screen text and copied into a one line text in the cell. It’s still holding the white space but it doesn’t look right with lines merging into each other. I have been trying to research anything that will loop in the cell to insert new lines in the cell. These are notes I could't get right.
The screen has 24 rows and 80 spaces wide (which translates well to text characters in excelusing the Len formula)There are nospecific text to reference before and after using Chr(10) like other examples. I need this to insert a new line every 80 characters x 24 . Any ideas are appreciated
The screen has 24 rows and 80 spaces wide (which translates well to text characters in excelusing the Len formula)There are nospecific text to reference before and after using Chr(10) like other examples. I need this to insert a new line every 80 characters x 24 . Any ideas are appreciated
Code:
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana]SubFormatCell()[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] 'splits Text active cell using ALT+10 char asseparator[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Dim FixForm As Range[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] i = 24[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Const LineLength As Long = 80[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Dim str As String[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] 'str = "Line 1" & vbLf &"Line 2" & vbLf & "Line 3"[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line1 = Mid(cl.Value, 1, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line2 = Mid(cl.Value, 81, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line3 = Mid(cl.Value, 161, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line4 = Mid(cl.Value, 241, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line5 = Mid(cl.Value, 321, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line6 = Mid(cl.Value, 401, 80)[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Line7 = Mid(cl.Value, 481, 80)[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Line8 = Mid(cl.Value, 561, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line9 = Mid(cl.Value, 641, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line10 = Mid(cl.Value, 721, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line11 = Mid(cl.Value, 801, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line12 = Mid(cl.Value, 881, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line13 = Mid(cl.Value, 961, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line14 = Mid(cl.Value, 1041, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line15 = Mid(cl.Value, 1121, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line16 = Mid(cl.Value, 1201, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line17 = Mid(cl.Value, 1281, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line18 = Mid(cl.Value, 1361, 80)[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Line19 = Mid(cl.Value, 1441, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line20 = Mid(cl.Value, 1521, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line21 = Mid(cl.Value, 1601, 80)[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Line22 = Mid(cl.Value, 1681, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line23 = Mid(cl.Value, 1761, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Line24 = Mid(cl.Value, 1841, 80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] For Each cl InActiveSheet.Range("FixForm")[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] If InStr(cl.Value, " ") >0 Then[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] 'SUBstitute(FixForm,""," "/n,80)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] 'cl.Value = Replace(cl.Value,Mid(cl.Value, 500, 1), " " & vbNewLine, 1, 1, vbTextCompare)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] 'WorksheetFunction.Substitute(cl,"Old_string", "Replacement_string", Instance_num)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] cl.Value = InStr(cl.Value, Line1)& Chr(10) _[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] & InStr(cl.Value, Line2) &Chr(10) _[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] & InStr(cl.Value, Line3) &Chr(10) _[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] End If[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] 'Statements to be executed inside the loop[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] Next cl[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] ' ActiveCell.FormulaR1C1 = ""& Chr(10) & ""[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] 'totalloop = UBound(i)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana] 'Range(ActiveCell.Row, ActiveCell.Column)[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT=Verdana]End Sub[/FONT][/COLOR]
Last edited by a moderator: