Sorting data by column headers I add

kwdennis

New Member
Joined
Jun 6, 2019
Messages
15
Currently using this to move a list of names to my headers on another sheet but when I add to the list and update my headers I need to resort my data columns as the new header column is added in alphabetically

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Application.CountIf(Range("A:A"), Target) > 1 Then
    
    MsgBox "Duplicate Data!", vbCritical, "Remove Duplicate"
    
    Target.Value = ""

    End If
    
    With Sheets("My_Setup")
    
        .Range("A2:A51").Sort key1:=.Range("A2"), order1:=xlAscending, Header:=xlNo, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    
    End With
End Sub


VBA Code:
Sub AddMyHeaders()

    Worksheets("My_Setup").Range("A2:A51").Copy
    Worksheets("My_Sagas").Range("E1").PasteSpecial Transpose:=True

'AutoFit All Columns on Worksheet
    Worksheets("My_Sagas").Range("E:BB").EntireColumn.AutoFit

End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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