View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Split row into multiply rows based on combined values in a cell and then make the values unique

Hi Johan,

Am Tue, 26 Mar 2019 04:10:25 -0700 (PDT) schrieb :

For example;
ColumnA ColumnB ColumnC ColumnD
AA123;BB123;CC123 blabla boeboe tjatja

Should be then;
ColumnA ColumnB ColumnC ColumnD
AA123 blabla boeboe tjatja
BB123 blabla boeboe tjatja
CC123 blabla boeboe tjatja


try:

Sub Test()
Dim varData1 As Variant, varData2 As Variant, varTmp As Variant
Dim LRow As Long, i As Long, n As Long

n = 1
'Modify sheet name here
With Sheets("Sheet1")
LRow = .Cells(.Rows.Count, 1).End(xlUp).Row
'Modify the range here
varData1 = .Range("A1:A" & LRow)
varData2 = .Range("B1:D" & LRow)
For i = LBound(varData1) To UBound(varData1)
varTmp = Split(varData1(i, 1), ";")
.Cells(n, 1).Resize(UBound(varTmp) + 1) = _
Application.Transpose(varTmp)
.Range(.Cells(n, "B"), .Cells(n + UBound(varTmp), "D")) _
= Application.Index(varData2, i)
n = n + UBound(varTmp) + 1
Next
End With
End Sub


Regards
Claus B.
--
Windows10
Office 2016