Populate Rows & Columns by Comma Split

airforceone

Board Regular
Joined
Feb 14, 2022
Messages
201
Office Version
  1. 2019
  2. 2016
Platform
  1. 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

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
CodeSellerBuyerSellerBuyer
A0002Robert Smith (18/Male/Hospitalized/Alien/STUDENT), Maria Garcia (43/Female/Hospitalized/Alien/FARMER)Mary Smith (2/Male/Hospitalized/Alien/JOBLESS)21
A0001Gerald 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)13


EXPECTED
CodeSellerBuyerSellerBuyer
A0002Robert Smith (18/Male/Hospitalized/Alien/STUDENT)Mary Smith (2/Male/Hospitalized/Alien/JOBLESS)21
A0002Maria Garcia (43/Female/Hospitalized/Alien/FARMER)Mary Smith (2/Male/Hospitalized/Alien/JOBLESS)21
A0001Gerald Golbuno (22/Male/Hospitalized/Alien/STUDENT)Maria Hernandez (34/Female/Hospitalized/Alien/JOBLESS)13
A0001Gerald Golbuno (22/Male/Hospitalized/Alien/STUDENT)James Johnson (40/Male/Hospitalized/Alien/JOBLESS)13
A0001Gerald Golbuno (22/Male/Hospitalized/Alien/STUDENT)Maria Martinez (37/Female/Hospitalized/Alien/JOBLESS)13
 
An alternative to VBA with Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Seller", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Seller"),
    #"Split Column by Delimiter1" = Table.ExpandListColumn(Table.TransformColumns(#"Split Column by Delimiter", {{"Buyer", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Buyer")
in
    #"Split Column by Delimiter1"
thanks for the time mate, but such code is a part of a bigger module.
also final report is a consolidated report from 4 sheets and don't know if its applicable to Office 2016, 2019 but thanks anyway mate :)
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
 
Upvote 0
Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
thanks mate will do, just need to find some free time :)
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,094
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