model_un
asked on
Replicate data base on single cell
Hello All.
I have a dataset with eleven columns. The last column/cell contains data (eg. '1, 2, 3') that needs to be (1) separated and (2) used to replicate the previous data.
Columns 1-10 will need to be replicated with each new row based on the 'separated' last cell. So if the last cell has two+ variables then the variable will be separated and the other data replicated.
So you go from:
A B
xxx 1, 2, 3
To:
A B
xxx 1
xxx 2
xxx 3
See dataset attached.
Thanks,
Fernando
refusal-charges-test-data.xlsx
I have a dataset with eleven columns. The last column/cell contains data (eg. '1, 2, 3') that needs to be (1) separated and (2) used to replicate the previous data.
Columns 1-10 will need to be replicated with each new row based on the 'separated' last cell. So if the last cell has two+ variables then the variable will be separated and the other data replicated.
So you go from:
A B
xxx 1, 2, 3
To:
A B
xxx 1
xxx 2
xxx 3
See dataset attached.
Thanks,
Fernando
refusal-charges-test-data.xlsx
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks The_Barman.
Question... when I ran your macro again using the test data... I notice that it is not returning the last line (the only one with a single entry).
Comments?
Question... when I ran your macro again using the test data... I notice that it is not returning the last line (the only one with a single entry).
Comments?
model_un, it works in my one!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the last line is my bad needed to add one to output...
Brian, over large data sets you will find that the cell level changes slow the whole code down considerably... I just made the schoolboy error of my output range being one row too small. (doh!)
refusal-charges-test-data.xlsm
Sub Run_Macro()
Dim Arr, Arr2
Dim ArrOut()
Z = 0
Arr = Sheets("Sheet1").UsedRange.Value
For x = 2 To UBound(Arr)
Arr2 = Split(Arr(x, 11), ",")
For y = 0 To UBound(Arr2)
Z = Z + 1
ReDim Preserve ArrOut(1 To 11, 1 To Z)
For i = 1 To 10
ArrOut(i, Z) = Arr(x, i)
Next i
ArrOut(11, Z) = Arr2(y)
Next y
Next x
Sheets("sheet2").Range("A2:K" & UBound(ArrOut, 2) + 1).Value = Application.Transpose(ArrOut)
End Sub
Brian, over large data sets you will find that the cell level changes slow the whole code down considerably... I just made the schoolboy error of my output range being one row too small. (doh!)
refusal-charges-test-data.xlsm
The_Barman,
Thanks, I'm very aware of... both of those points!
Unless a macro has a significant time-impact on the user, I tend to lean to the side of simplicity over speed. I'm very reluctant to give a user a solution which is beyond their capability to support.
Regards,
Brian.
Thanks, I'm very aware of... both of those points!
Unless a macro has a significant time-impact on the user, I tend to lean to the side of simplicity over speed. I'm very reluctant to give a user a solution which is beyond their capability to support.
Regards,
Brian.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you all.
In the end GowFlow's solution worked without freezing my system.
Thanks!
In the end GowFlow's solution worked without freezing my system.
Thanks!
refusal-charges-test-data.xlsm