Separate Comma values in the cell and replacing in a new row by copying the original content

mayaa_mmm

Board Regular
Joined
Jul 30, 2014
Messages
54
Office Version
  1. 2010
Platform
  1. Windows
I want to split the content in a column (Vendor 1, Vendor 2, Vendor 3) into different rows.

NameTypeNameVendor 1Vendor 2Vendor 3ManagerAvailable
Apple1KashmirPadma whole saleFruit Junction; Juice cornerHypercity; Star bazzarAnthonymultiple
Orange2AustraliaPadma whole sale;Fruit JunctionJuice cornerGopiSingle
Grapes3AustraliaPadma whole sale;Fruit JunctionHypercity; Star bazzarPreethiMultiple

<colgroup><col><col><col><col><col><col><col span="2"></colgroup><tbody>
</tbody>

Final outcome should be like below for every items.

NameTypeNameVendor 1Vendor 2Vendor 3ManagerAvailable
Apple1KashmirPadma whole saleAnthonymultiple
Apple1KashmirFruit JunctionAnthonymultiple
Apple1Kashmir Juice cornerAnthonymultiple
Apple1KashmirHypercityAnthonymultiple
Apple1KashmirStar bazzarAnthonymultiple

<colgroup><col><col><col><col><col><col><col span="2"></colgroup><tbody>
</tbody>


It will be helpful for us. It will save the tons of Time
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Using the sample data provided I have assumed:
Data is on Sheet1
Data starts in cell A1.
The code loops through column A until it reaches an empty cell.

Place the code in a standard module, i.e., Insert=>Module
The code loops through the data and generates new output in the columns to the right of the existing data.
Use the sample data provided to test the code.
Rich (BB code):
Option Explicit


Sub ParseData()
   Dim rngRow As Range        'column A entries to loop through
   Dim rowSource As Long      'source row
   Dim rowTarget As Long      'output row
   Dim colTarget As Long      'output column
   Dim arrVendor As Variant
   Dim col As Long            'column loop index
   Dim i As Long              'array loop index
   
   'initialize variables
   Set rngRow = Sheets("Sheet1").Range("A2")
   rowTarget = 1
   
   'loop through rows
   Do Until rngRow = ""
      rowSource = rngRow.Row
      
      'loop through columns
      For col = 4 To 6
         
         'does this cell contain a value?
         If Sheets("Sheet1").Cells(rowSource, col).Value <> "" Then
            
            'populate the vendor array, separate by semi colon
            arrVendor = Split(Sheets("Sheet1").Cells(rowSource, col).Value, ";")
            
            'loop through the array
            For i = LBound(arrVendor) To UBound(arrVendor)
               rowTarget = rowTarget + 1
               
               'output
               With Sheets("Sheet1")
                  .Range("J" & rowTarget).Value = .Range("A" & rowSource).Value  'name
                  .Range("K" & rowTarget).Value = .Range("B" & rowSource).Value  'type
                  .Range("L" & rowTarget).Value = .Range("C" & rowSource).Value  'area
                  .Cells(rowTarget, col + 9).Value = Trim(arrVendor(i))          'vendor
                  .Range("P" & rowTarget).Value = .Range("G" & rowSource).Value  'manager
                  .Range("Q" & rowTarget).Value = .Range("C" & rowSource).Value  'available
               End With
            Next i
         End If
         
      Next col


      'get next row
      Set rngRow = rngRow.Offset(1, 0)
   Loop


   'tidy up
   Set rngRow = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,854
Members
449,096
Latest member
Erald

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