Hello All, I need your advise, if it will be ok, to replace the "enter" character, from a VBA code, which split the data from wrapped text cells into different cells / rows.
Please find below the code. This works fine, but I would like to know if it is feasible to replace the "enter" with some other character. Does any other character, ruin the macro functionality? How should I add it?
With the current macro, users cannot use "enter" inside their text fields. If they start to submit enter and use more paragraphs inside the text field, the macro is not working ok - not taking all the data.
Any thoughts on this?
Thanks a lot
Sub Test()
Dim arrIn, arrLen, arrOut, totalRow As Long, i As Long, j As Long, k As Long, p As Long
With Sheets("Sheet1")
arrIn = .Range("A1").CurrentRegion.Value
ReDim arrLen(1 To UBound(arrIn, 1))
End With
For i = 2 To UBound(arrIn, 1)
For j = 1 To UBound(arrIn, 2)
If Len(arrIn(i, j)) Then
arrIn(i, j) = Split(arrIn(i, j), vbLf)
k = UBound(arrIn(i, j)) + 1
If arrLen(i) < k Then arrLen(i) = k
End If
Next j
Next i
arrLen(1) = 1
totalRow = 1
For i = 2 To UBound(arrLen)
totalRow = totalRow + arrLen(i)
Next i
ReDim arrOut(1 To totalRow, 1 To UBound(arrIn, 2))
p = 1
For i = 1 To UBound(arrIn, 1)
For j = 1 To UBound(arrIn, 2)
If IsArray(arrIn(i, j)) Then
For k = 0 To UBound(arrIn(i, j))
arrOut(p + k, j) = arrIn(i, j)(k)
Next k
Else
arrOut(p, j) = arrIn(i, j)
End If
Next j
p = p + arrLen(i)
Next i
With Sheets.Add(after:=Sheets(Sheets.Count))
With .Range("A1").Resize(UBound(arrOut, 1), UBound(arrOut, 2))
.Value = arrOut
.EntireColumn.AutoFit
End With
End With
End Sub
Bookmarks