Populate Rows & Columns by Comma Split (DYNAMIC VERSION ver.2)

airforceone

Board Regular
Joined
Feb 14, 2022
Messages
201
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Populate Rows & Columns by Comma Split version 1

Good day mate, got the problem above solved!
but it would be a bit of a problem to implement since my sheet column is dynamic starting from 96 columns and 6000 rows on a quarterly period
would anyone kindly help this poor guy to implement a dynamic version based on given set of records :)

CODEeDateCol03Col04Col05Col06Col07Col08Col09Col10Col11Col12RepDateRepTimeComDateComTimeCol13Col14Col15Col16Col17Col18Col19SELLERBUYERCol19Col20Col21Col22Col23Col24Col25Col26Col27Col28Col29Col30Col31Col32Col33Col34Col35Col36Col37Col38Col39Col40Col41FPDateCol41Col42Col43FCDateCol43Col44Col45Col46Col47Col48Col49Col50Col51Col52Col53Col54Col55Col56Col57Col58Col59Col60Col61Col62Col63Col64Col65Col66Col67Col68Col69Col70Col71
A00012024-03-07 11:25:11Data 00Data 01Data 02Data 03Data 04Data 05Data 06Data 07Data 08Data 092024-03-0613:40:002024-03-0516:09:00Data 00Data 01Data 02Data 03Data 04Data 05Data 06Robert Smith (18/Male/Hospitalized/Alien/STUDENT), Maria Garcia (43/Female/Hospitalized/Alien/FARMER)Mary Smith (2/Male/Hospitalized/Alien/JOBLESS)Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 00Data 002024-03-07Data 00Data 01Data 022024-03-07Data 00Data 01Data 02Data 03Data 04Data 05Data 06Data 07Data 08Data 09Data 10Data 11Data 12Data 13Data 14Data 15Data 16Data 17Data 18Data 19Data 20Data 21Data 22Data 23Data 24Data 25Data 26Data 27Data 28
A00022024-03-07 11:25:12Data 00Data 01Data 02Data 03Data 04Data 05Data 06Data 07Data 08Data 092024-03-0713:40:012024-03-0616:09:01Data 00Data 01Data 02Data 03Data 04Data 05Data 06Gerald 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)Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 01Data 012024-03-08Data 00Data 01Data 022024-03-08Data 00Data 01Data 02Data 03Data 04Data 05Data 06Data 07Data 08Data 09Data 10Data 11Data 12Data 13Data 14Data 15Data 16Data 17Data 18Data 19Data 20Data 21Data 22Data 23Data 24Data 25Data 26Data 27Data 28
A00032024-03-07 11:25:13Data 00Data 01Data 02Data 03Data 04Data 05Data 06Data 07Data 08Data 092024-03-0813:40:022024-03-0716:09:02Data 00Data 01Data 02Data 03Data 04Data 05Data 06Michael 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)Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 02Data 022024-03-09Data 00Data 01Data 022024-03-09Data 00Data 01Data 02Data 03Data 04Data 05Data 06Data 07Data 08Data 09Data 10Data 11Data 12Data 13Data 14Data 15Data 16Data 17Data 18Data 19Data 20Data 21Data 22Data 23Data 24Data 25Data 26Data 27Data 28
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I assume :
1. Your Seller column always in ("X" column which is 24)
2. Your Buyer column always in ("Y" column which is 25)
3. Your Data always start at "A2" (A1 Header)

Try this :

Code:
Option Explicit

Private Sub Sync()
    Dim oWs As Worksheet
    Dim arrData, arrSeller, arrBuyer, arrReport As Variant
    Dim iLastColumn, iLastRow, arrayCounter, i, j, k, l As Long
  
    Set oWs = ThisWorkbook.Worksheets("Sheet1")'YOUR SHEET NAME
    iLastColumn = oWs.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    iLastRow = oWs.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
  
    arrData = oWs.Range("A2:" & Split(Cells(1, iLastColumn).Address, "$")(1) & iLastRow).Value
  
    For i = LBound(arrData) To UBound(arrData)
        arrSeller = Split(arrData(i, 24), ",")
        arrBuyer = Split(arrData(i, 25), ",")

        arrayCounter = arrayCounter + ((UBound(arrSeller) + 1) * (UBound(arrBuyer) + 1))
    Next i

    ReDim arrReport(1 To arrayCounter, 1 To iLastColumn)

    arrayCounter = 1

    For i = LBound(arrData) To UBound(arrData)
        arrSeller = Split(arrData(i, 24), ",")
        arrBuyer = Split(arrData(i, 25), ",")

        For j = LBound(arrSeller) To UBound(arrSeller)
            For k = LBound(arrBuyer) To UBound(arrBuyer)
                For l = 1 To iLastColumn
                    If l = 24 Then
                        arrReport(arrayCounter, l) = arrSeller(j)
                    ElseIf l = 25 Then
                        arrReport(arrayCounter, l) = arrBuyer(k)
                    Else
                        arrReport(arrayCounter, l) = arrData(i, l)
                    End If
                Next l
              
                arrayCounter = arrayCounter + 1
            Next k
        Next j
    Next i

    oWs.Range("A2").Resize(UBound(arrReport, 1), UBound(arrReport, 2)).Value = arrReport
End Sub
 
Last edited:
Upvote 0
Solution
I assume :
1. Your Seller column always in ("X" column which is 24)
2. Your Buyer column always in ("Y" column which is 25)
3. Your Data always start at "A2" (A1 Header)
safe to say yes, but in the event I need to search such header I used below code to locate
VBA Code:
    For iCtr = 1 To ColSource
        If UCase(Cells(1, iCtr).Value) Like "*Seller*" Then
        End If
also, if the need arise I just have to change the following line of code right?
arrSeller = Split(arrData(i, 24), ",")
arrBuyer = Split(arrData(i, 25), ",")
 
Upvote 0
safe to say yes, but in the event I need to search such header I used below code to locate
VBA Code:
    For iCtr = 1 To ColSource
        If UCase(Cells(1, iCtr).Value) Like "*Seller*" Then
        End If
also, if the need arise I just have to change the following line of code right?
To make it more flexible, you can populate Header row to an array first and find the column index through looping with your code above, after you get the proper index column for "Seller" and "Buyer" you can combine with code from me :

VBA Code:
arrSeller = Split(arrData(i, 24), ",")
arrBuyer = Split(arrData(i, 25), ",")
 
Upvote 0
To make it more flexible, you can populate Header row to an array first and find the column index through looping with your code above, after you get the proper index column for "Seller" and "Buyer" you can combine with code from me :

VBA Code:
arrSeller = Split(arrData(i, 24), ",")
arrBuyer = Split(arrData(i, 25), ",")
thanks mate :)
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,082
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top