Hi Guys
I'm no VBA coder but have used the 'Record Macro' tool to create a basic macro in my Personal Macro Workbook in Excel to tidy up some excel exports that are regularly dumped from one our doc management systems. The recorded script is as below. My basic question is this: I want to be able to run this macro across whatever workbook I have open regardless of the workbook/worksheet name but by default the 'Record Macro' tool appends the name of the workbook and worksheet that I was working in when I recorded the macro. Is there a generic syntax I can use instead?
Thanks!
I'm no VBA coder but have used the 'Record Macro' tool to create a basic macro in my Personal Macro Workbook in Excel to tidy up some excel exports that are regularly dumped from one our doc management systems. The recorded script is as below. My basic question is this: I want to be able to run this macro across whatever workbook I have open regardless of the workbook/worksheet name but by default the 'Record Macro' tool appends the name of the workbook and worksheet that I was working in when I recorded the macro. Is there a generic syntax I can use instead?
Thanks!
Code:
ActiveSheet.Range("Name of file[#All]").RemoveDuplicates Columns _
:=Array(4, 5), Header:=xlYes
ActiveWindow.LargeScroll ToRight:=1
ActiveWorkbook.Worksheets("Name of worksheet").ListObjects( _
"Name of file").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Name of worksheet").ListObjects( _
"Name of file").Sort.SortFields.Add Key:=Range( _
"Name of file[[#All],[Email]]"), SortOn:=xlSortOnValues, Order _
:=xlAscending, DataOption:=xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Name of worksheet").ListObjects( _
"Name of file").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Last edited by a moderator: