Column Order from List

Big_Dawg

New Member
Joined
Jan 15, 2008
Messages
27
Looking for a dynamic macro to reorder columns in a worksheet from a list of column headings Column A in another worksheet.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Big_Dawg

New Member
Joined
Jan 15, 2008
Messages
27
I have this down. Struggling with the array coming from a list.

I need the array to come from a list from another worksheet.

How to change below to reference list from worksheet?

arrColOrder = Array("Header1", "Header2", "Header3", "Header4", "Header5", _
"Header6", "Header7", "Header8", "Header9", "Header10"
)
 

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,400
The red is the sheet and range with the column order list.

Code:
Sub Reorder_Columns()
    
    Dim cell As Range
    Dim Found As Range
    Dim counter As Integer
    
    counter = 1
    
    Application.ScreenUpdating = False
    
    For Each cell In [COLOR="Red"]Sheets("Sheet1").Range("A1:A10")[/COLOR]
    
        Set Found = Rows("1:1").Find(cell.Value, LookIn:=xlValues, LookAt:=xlWhole, _
                          SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
        
        If Not Found Is Nothing Then
            If Found.Column <> counter Then
                Found.EntireColumn.Cut
                Columns(counter).Insert Shift:=xlToRight
                Application.CutCopyMode = False
            End If
            counter = counter + 1
        End If
        
    Next cell
    
    Application.ScreenUpdating = True
    
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,580
Messages
5,637,211
Members
416,961
Latest member
sigrid6940

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
Top