Copy Paste delete loop if column has data

hetal247

New Member
Joined
Dec 21, 2011
Messages
18
Hi,

I am looking for a code that will help with what I want to achieve. I have a table where I have to split a column using text-to-columns. The number of columns created after will vary time to time.

What I now want to do is copy the rows to a certain column and then for each of the columns created after text-to-column, input the data and repeat the process until the last create column has data.

e.g my table looks like this
IDNameItems
1J BloggsTable,Chairs,Desk,Stapler
2R BearChair
3P ParrotDesk,Table

<tbody>
</tbody>

So I need to split the items columns which will then show my table as:

IDNameItem1Item2Item3Item4
1J BloggsTableChairsDeskStapler
2R BearChair
3P ParrotDeskTable

<tbody>
</tbody>

So I now want to be able to copy the id and names and bring back the items until the last cell so my end table will look like this:

IDNameItem
1J BloggsTable
2R BearChair
3P ParrotDesk
1J BloggsChairs
3P ParrotTable
1J BloggsDesk
1J BloggsStapler

<tbody>
</tbody>


I might be asking a lot for this to happen but wondered if there was a way this could be achieved.

Appreciate any help that is given.

Kind regards
Hetal
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
This code will create the last table from the first table, if that's acceptable.
Results start "E1".
Code:
[COLOR="Navy"]Sub[/COLOR] MG25May23
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Sp [COLOR="Navy"]As[/COLOR] Variant, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ray()
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] n = 0 To 100
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    Sp = Split(Dn.Offset(, 2), ",")
    [COLOR="Navy"]If[/COLOR] n <= UBound(Sp) [COLOR="Navy"]Then[/COLOR]
        c = c + 1
        ReDim Preserve Ray(1 To 3, 1 To c)
        Ray(1, c) = Dn.Value
        Ray(2, c) = Dn.Offset(, 1)
        Ray(3, c) = Sp(n)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]Next[/COLOR] n
Range("E1").Resize(c, 3) = Application.Transpose(Ray)
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Hi Mick,

Thank you for your response. How do i amend the code so it refers to the correct column that needs to be split? My column that needs to be split in this case is column L.

kind regards

Hetal
 
Upvote 0
If your column for splitting is "L" then that would imply the first column in your data is "J", so Replace the 3rd line in code as below. shown :-
Code:
[COLOR=#000080]Set[/COLOR] Rng = Range("J1"), Range("J" & Rows.Count).End(xlUp))
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,558
Members
449,038
Latest member
Guest1337

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