I'm writing a VBA Macro which splits a long String in a lot of substrings and copies them in new Columns.
My problem now is, that there is a Column called "Spare Parts" and in that Column there are only Cells which contain wrapped text.
The lines in the cells, except of the first 3, always look the same:
---> Spare Part ID(10Digits) , Spare Part Name , Number of Units , Price per Unit
And I need to split those 4 parts into individual strings.
I already managed to split those 4 parts and copy them in new Columns if there is only one String in a cell.(=No wrapped cell)
But I dont know how to do that in a Wrapped Cell?
I think I need to get the index of the position of the first "line break" character and save that value and then work with that ?
Somebody has any ideas and maybe some code examples or something like that?
can you post a workbook (zip first) with a sample of the data
probably split the cell on chr(10) (but hard to guess without some sample of the data), then loop the array and split each element to put the value into individual cells
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
As both of you guys said, I did the loop with Chr(10)
Code:
srcRow = 1
dstRow = 1
NumRows = Range("A2", Range("A2").End(xlDown)).Rows.Count
For x2 = 1 To NumRows
srcRow = srcRow + 1
dstRow = dstRow + 1
strLen = Len(Cells(srcRow, "B"))
If strLen <> 0 Then
test = Replace(Cells(srcRow, "B"), Chr(10), "", 1, -1, vbTextCompare)
x = Len(test)
anzLeer = strLen - x
rightLine = Cells(srcRow, "B").Value
For o = 0 To anzLeer
newLineLen = InStr(rightLine, Chr(10))
leftLine = Left(rightLine, newLineLen)
'#########SPLIT#########
rightLine = Replace(rightLine, leftLine, "")
If o = anzLeer Then
leftLine = rightLine
End If
MsgBox (leftLine)
Next
End If
Next
End Sub
If you insert this in my previous uploaded sample, it will return every line in all cells one by one as I wanted.
Now I only need to implement the rest of the code to split these lines i get returned.
But thats the lesser Problem thank you guys for helping