Make a worksheet active

stooven

New Member
Joined
Oct 12, 2006
Messages
15
This one may be easy but I'm having trouble finding the solution in the archive/help files because so many irrelavent results come up.

I want to make a worksheet active. I know how to do this ordinarily but the catch is that I can't refer to it by name because the name changes with each project. My project should start off with a single worksheet then add two more worksheets and then select the original one again. My script is this:

Code:
Sub Program()
Dim cell As Range
Dim aRange As Range
Set aRange = Range(Range("I2"), Range("I65536").End(xlUp))

    Sheets.Add
        Sheets("Sheet1").Select
        Sheets("Sheet1").Name = "sheetx"
    Sheets.Add
        Sheets("Sheet2").Select
        Sheets("Sheet2").Name = "sheety"
        
    Selection.AutoFilter (This is where I want to autofilter my original page but can't refer to it by name)

Any input is appreciated!

Thanks,
Steve
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Code:
dim thissht as string

thissht = activesheet.name

then at the end you can refer to the sheet stored in the thissht string variable.

HTH
 
Upvote 0
Steve

Try this.
Code:
Sub Program()
Dim cell As Range
Dim aRange As Range
Dim ws As Worksheet
    Set ws = ActiveSheet
    Set aRange = ws.Range(ws.Range("I2"), ws.Range("I65536").End(xlUp))

    Sheets.Add
    ActiveSheet.Name = "sheetx"
    Sheets.Add
    ActiveSheet.Name = "sheety"
       
    aRange.AutoFilter
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

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