Code to move data in 1 column to multiple columns

Pjam

Board Regular
Joined
Jun 4, 2008
Messages
139
Hi,

I am trying to move data alot of data in one column to everyother column in the spreadsheet when an ID changes.


i have all this information in column A alot.

for example

i would like to see all 1's in B the next value 2 in column D etc any ideas?

1
1
1
1
1
2
2
2
2
2
3
3
3
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try :-
Code:
[COLOR=navy]Sub[/COLOR] MG31Mar40
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range
[COLOR=navy]Dim[/COLOR] Dn [COLOR=navy]As[/COLOR] Range
[COLOR=navy]Dim[/COLOR] Ac [COLOR=navy]As[/COLOR] [COLOR=navy]Integer[/COLOR]
[COLOR=navy]Dim[/COLOR] c [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]Dim[/COLOR] oMax [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & rows.Count).End(xlUp))
ReDim Ray(1 To Rng.Count, 1 To Columns.Count)
Ac = 1
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
    c = c + 1
        oMax = Application.Max(c, oMax)
           Ray(c, Ac) = Dn
              [COLOR=navy]If[/COLOR] Dn <> Dn.Offset(1) [COLOR=navy]Then[/COLOR] Ac = Ac + 1: c = 0
                [COLOR=navy]Next[/COLOR] Dn
Rng.ClearContents
Range("A1").Resize(oMax, Ac) = Ray
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
Code:
Sub Copy_IDs()
    
    Dim rngUniques As Range, rngFilter As Range, rngCopy As Range
    Dim cell As Range, counter As Long
    
    Application.ScreenUpdating = False
    
    ' Add header (temporary)
    Range("A1").Insert Shift:=xlDown
    Range("A1").Value = "IDs"
    
    Set rngFilter = Range("A1", Range("A" & Rows.Count).End(xlUp))
    Set rngCopy = Range("A2", Range("A" & Rows.Count).End(xlUp))
    
    rngFilter.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Set rngUniques = rngCopy.SpecialCells(xlCellTypeVisible)
    If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
    
    For Each cell In rngUniques
        counter = counter + 1
        rngFilter.AutoFilter Field:=1, Criteria1:=cell.Value
        rngCopy.SpecialCells(xlCellTypeVisible).Copy Destination:=Cells(1, counter * 2)
    Next cell
    
    ActiveSheet.AutoFilterMode = False
    
    ' Remove header
    Range("A1").Delete Shift:=xlUp
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,881
Members
452,948
Latest member
Dupuhini

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