airforceone
Board Regular
- Joined
- Feb 14, 2022
- Messages
- 201
- Office Version
- 2019
- 2016
- Platform
- Windows
Good day mate, need some guidance here
1. got a code with some loop error and
2. would like to parse the cell value into adjacent column
attached here is the source, Code Result and Expected Result (Hopefully)
source
Code Result (With some kind of Loop error, when run)
Expected Result
1. got a code with some loop error and
2. would like to parse the cell value into adjacent column
attached here is the source, Code Result and Expected Result (Hopefully)
source
Michael Smith (49/Male/Hospitalized/Alien/DRIVER) |
James Smith (18/Male/Hospitalized/Alien/JOBLESS) |
Robert Smith (18/Male/Hospitalized/Alien/STUDENT) |
Maria Garcia (43/Female/Hospitalized/Alien/FARMER) |
David Smith (15/Female/Deceased/Alien/STUDENT) |
Maria Rodriguez (46/Female/Hospitalized/Alien/FARMER) |
Mary Smith (2/Male/Hospitalized/Alien/JOBLESS) |
Gerald Golbuno (22/Male/Hospitalized/Alien/STUDENT) |
Maria Hernandez (34/Female/Hospitalized/Alien/JOBLESS) |
Maria Martinez (37/Female/Hospitalized/Alien/JOBLESS) |
James Johnson (40/Male/Hospitalized/Alien/JOBLESS) |
Maria Michael (37/Female/Hospitalized/Alien/JOBLESS) |
James Biggins (38/Male/Hospitalized/Alien/JOBLESS) |
Code Result (With some kind of Loop error, when run)
Michael Smith (49/Male/Hospitalized/Alien/DRIVER) | Michael | Smith | (49 | Male | Hospitalized | Alien | DRIVER) |
James Smith (18/Male/Hospitalized/Alien/JOBLESS) | James | Smith | (18 | Male | Hospitalized | Alien | JOBLESS) |
Robert Smith (18/Male/Hospitalized/Alien/STUDENT) | Robert | Smith | (18 | Male | Hospitalized | Alien | STUDENT) |
Maria Garcia (43/Female/Hospitalized/Alien/FARMER) | Maria | Garcia | (43 | Female | Hospitalized | Alien | FARMER) |
David Smith (15/Female/Deceased/Alien/STUDENT) | David | Smith | (15 | Female | Deceased | Alien | STUDENT) |
Maria Rodriguez (46/Female/Hospitalized/Alien/FARMER) | Maria | Rodriguez | (46 | Female | Hospitalized | Alien | FARMER) |
Mary Smith (2/Male/Hospitalized/Alien/JOBLESS) | Mary | Smith | (2 | Male | Hospitalized | Alien | JOBLESS) |
Gerald Golbuno (22/Male/Hospitalized/Alien/STUDENT) | Gerald | Golbuno | (22 | Male | Hospitalized | Alien | STUDENT) |
Maria Hernandez (34/Female/Hospitalized/Alien/JOBLESS) | Maria | Hernandez | (34 | Female | Hospitalized | Alien | JOBLESS) |
Maria Martinez (37/Female/Hospitalized/Alien/JOBLESS) | Maria | Martinez | (37 | Female | Hospitalized | Alien | JOBLESS) |
James Johnson (40/Male/Hospitalized/Alien/JOBLESS) | James | Johnson | (40 | Male | Hospitalized | Alien | JOBLESS) |
Maria Michael (37/Female/Hospitalized/Alien/JOBLESS) | Maria | Michael | (37 | Female | Hospitalized | Alien | JOBLESS) |
James Biggins (38/Male/Hospitalized/Alien/JOBLESS) | James | Biggins | (38 | Male | Hospitalized | Alien | JOBLESS) |
CODE RESULT | |||||||
Expected Result
Michael Smith (49/Male/Hospitalized/Alien/DRIVER) | Michael Smith | 49 | Male | Hospitalized | Alien | DRIVER |
James Smith (18/Male/Hospitalized/Alien/JOBLESS) | James Smith | 18 | Male | Hospitalized | Alien | JOBLESS |
Robert Smith (18/Male/Hospitalized/Alien/STUDENT) | Robert Smith | 18 | Male | Hospitalized | Alien | STUDENT |
Maria Garcia (43/Female/Hospitalized/Alien/FARMER) | Maria Garcia | 43 | Female | Hospitalized | Alien | FARMER |
David Smith (15/Female/Deceased/Alien/STUDENT) | David Smith | 15 | Female | Deceased | Alien | STUDENT |
Maria Rodriguez (46/Female/Hospitalized/Alien/FARMER) | Maria Rodriguez | 46 | Female | Hospitalized | Alien | FARMER |
Mary Smith (2/Male/Hospitalized/Alien/JOBLESS) | Mary Smith | 2 | Male | Hospitalized | Alien | JOBLESS |
Gerald Golbuno (22/Male/Hospitalized/Alien/STUDENT) | Gerald Golbuno | 22 | Male | Hospitalized | Alien | STUDENT |
Maria Hernandez (34/Female/Hospitalized/Alien/JOBLESS) | Maria Hernandez | 34 | Female | Hospitalized | Alien | JOBLESS |
Maria Martinez (37/Female/Hospitalized/Alien/JOBLESS) | Maria Martinez | 37 | Female | Hospitalized | Alien | JOBLESS |
James Johnson (40/Male/Hospitalized/Alien/JOBLESS) | James Johnson | 40 | Male | Hospitalized | Alien | JOBLESS |
Maria Michael (37/Female/Hospitalized/Alien/JOBLESS) | Maria Michael | 37 | Female | Hospitalized | Alien | JOBLESS |
James Biggins (38/Male/Hospitalized/Alien/JOBLESS) | James Biggins | 38 | Male | Hospitalized | Alien | JOBLESS |
EXPECTED RESULT | ||||||
VBA Code:
Private Sub Parse_String()
Dim rngSource As Range
Dim LastRow As Long, iLoop As Long
Dim LastColHeader As String
LastRow = Sheets("SOURCE").UsedRange.Rows.Count
With Sheets("SOURCE")
Set rngSource = Sheets("SOURCE").Range("A1:A" & LastRow)
End With
Dim Targetcel As Range
For Each Targetcel In rngSource
Targetcel.Value = WorksheetFunction.Substitute(Targetcel.Value, "-", ", ")
Next Targetcel
For iLoop = 1 To LastRow
LastColHeader = Split(Cells(iLoop, 2).Address, "$")(1)
rngSource.TextToColumns _
Destination:=Range(LastColHeader & iLoop & ":" & LastColHeader & iLoop & ":" & LastColHeader & iLoop & ":" & LastColHeader & iLoop & ":" & LastColHeader & iLoop), _
DataType:=xlDelimited, _
Tab:=False, _
Semicolon:=False, _
Comma:=False, _
Space:=True, _
Other:=True, _
OtherChar:="/"
Next iLoop
End Sub ' Parse_String