Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2016 VBA - select current sheet regardless of name 1

Status
Not open for further replies.

pendle666

Technical User
Jan 30, 2003
295
GB
Hello

Each month I need to create a report from some extracted data. There is just one worksheet, and the name varies from month to month.

What I'd like to do is have Excel just select that Worksheet. What the macro needs to do is sort the records into a specific order - the employee number, and that's where I'm stuck.

The current code is:

[pre]ActiveWorkbook.Worksheets("T53").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("T53").AutoFilter.Sort.SortFields.Add Key:=Range( _
"E1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal[/pre]

T53 happens to be the name of the worksheet this time, but it varies. I've tried ActiveWorkbook.ActiveWorksheet without a name and also tried With ActiveWorksheet, but I can't get the sort function to work.

Can anyone help please?

thanks




thank you for helping

____________
Pendle
 
If the code is in other workbook and processed data is in other workbook containing single worksheet, you can refer with ActiveWorkbook.Worksheets(1).
Excel has no ActiveWorksheet object, use ActiveSheet instead, it is a child object (property) for Application, Window and Workbook objects.

combo
 
Hello

The macro itself is sitting in personal.xlsb and there are no other macros in the workbook I'm needing to run this on.




thank you for helping

____________
Pendle
 
That's worked perfectly, thank you.

thank you for helping

____________
Pendle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top