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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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"
)
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,166
Members
448,870
Latest member
max_pedreira

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