Getting macro to reference current sheet rather than sheet name

markman235

New Member
Joined
May 10, 2011
Messages
46
Hi everyone,

I have a macro that creates a new tab every time it runs. I have another macro to later delete that new tab, but I can't get it to reference the active sheet rather than the sheet name.

Here is the Macro that I have by using the record macro function. The current sheet on here is "Sheet5", but I just need it to reference the active sheet.

Cells.Select
Cells.EntireColumn.AutoFit
Rows("1:1").Select
Selection.AutoFilter
Range("B5").Select
Sheets("Sheet5").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Macro paste").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Summary").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Vendors").Select
ActiveWindow.SelectedSheets.Visible = False
Range("B2").Select
End Sub

You guys are the best!!

Mark
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi,
To answer your question, you can use
VBA Code:
ActiveSheet.Delete

As a side comment, you should get rid of all your "Select" instructions ...
 
Upvote 0

Forum statistics

Threads
1,214,574
Messages
6,120,329
Members
448,956
Latest member
Adamsxl

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