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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

patrickmuldoon99

Active Member
Joined
Jun 27, 2006
Messages
345
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
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
 

Forum statistics

Threads
1,136,267
Messages
5,674,730
Members
419,523
Latest member
Urnovio

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
Top