Apply macro to active worksheet

  • Hi folks,


    I'm setting up a spreadsheet for a local charity run kids club and would like to include a macro that will arrange the names A to Z by surname. I can get the macro working on a specific page, but when I add a new page the macro wont work. I have attempted to edit the code from specific sheet names to 'ActiveSheet' but this is incorrect. Can anyone help?


    Here is the code for my macro:-


    Sub NameSort()
    '
    ' NameSort Macro
    '


    '
    Selection.EntireColumn.Hidden = False
    Columns("A:A").Select
    ActiveWorkbook.Worksheets("12.03.18").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("12.03.18").Sort.SortFields.Add Key:=Range( _
    "A2:A102"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    With ActiveWorkbook.Worksheets("12.03.18").Sort
    .SetRange Range("A1:T102")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    Range("D:D,F:F,H:H,J:J,L:L").Select
    Range("L1").Activate
    Selection.EntireColumn.Hidden = True
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!