airforceone
Board Regular
- Joined
- Feb 14, 2022
- Messages
- 201
- Office Version
- 2019
- 2016
- Platform
- Windows
Good day mate, need some advice here again
I would like to Populate Rows & Columns based on number of Comma Split
below code works for a single column, but would like to implement it to a couple of columns
DATA SOURCE
EXPECTED
I would like to Populate Rows & Columns based on number of Comma Split
below code works for a single column, but would like to implement it to a couple of columns
VBA Code:
Sub Split_Seller_and_Buyer()
' =====================
' working
' =====================
Dim lastrow As Integer, i As Integer
Dim descriptions() As String
Dim Item As Variant
With Worksheets("sht01")
lastrow = .Range("C1").End(xlDown).Row
For i = lastrow To 2 Step -1
If InStr(1, .Range("C" & i).Value, ",") <> 0 Then
descriptions = Split(.Range("C" & i).Value, ",")
End If
For Each Item In descriptions
.Range("C" & i).Value = Item
.Rows(i).Copy
.Rows(i).Insert
Next Item
.Rows(i).EntireRow.Delete
Next i
End With
End Sub ' Split_Seller_and_Buyer
DATA SOURCE
Code | Seller | Buyer | Seller | Buyer |
A0002 | Robert Smith (18/Male/Hospitalized/Alien/STUDENT), Maria Garcia (43/Female/Hospitalized/Alien/FARMER) | Mary Smith (2/Male/Hospitalized/Alien/JOBLESS) | 2 | 1 |
A0001 | Gerald Golbuno (22/Male/Hospitalized/Alien/STUDENT) | Maria Hernandez (34/Female/Hospitalized/Alien/JOBLESS), James Johnson (40/Male/Hospitalized/Alien/JOBLESS), Maria Martinez (37/Female/Hospitalized/Alien/JOBLESS) | 1 | 3 |
EXPECTED
Code | Seller | Buyer | Seller | Buyer |
A0002 | Robert Smith (18/Male/Hospitalized/Alien/STUDENT) | Mary Smith (2/Male/Hospitalized/Alien/JOBLESS) | 2 | 1 |
A0002 | Maria Garcia (43/Female/Hospitalized/Alien/FARMER) | Mary Smith (2/Male/Hospitalized/Alien/JOBLESS) | 2 | 1 |
A0001 | Gerald Golbuno (22/Male/Hospitalized/Alien/STUDENT) | Maria Hernandez (34/Female/Hospitalized/Alien/JOBLESS) | 1 | 3 |
A0001 | Gerald Golbuno (22/Male/Hospitalized/Alien/STUDENT) | James Johnson (40/Male/Hospitalized/Alien/JOBLESS) | 1 | 3 |
A0001 | Gerald Golbuno (22/Male/Hospitalized/Alien/STUDENT) | Maria Martinez (37/Female/Hospitalized/Alien/JOBLESS) | 1 | 3 |