+ Reply to Thread
Results 1 to 6 of 6

how to reference sheets properly?

  1. #1
    Registered User
    Join Date
    05-03-2010
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    59

    how to reference sheets properly?

    if i want to call a sheet using something like:

    Please Login or Register  to view this content.
    is it possible to make it so that it selects the first sheet in the workbook, regardless of its name? or the second sheet regardless of its name etc; This current code fails every time i have a workbook with costum named sheets

  2. #2
    Registered User
    Join Date
    05-25-2010
    Location
    Trinidad
    MS-Off Ver
    Excel 2007
    Posts
    29

    Re: how to reference sheets properly?

    try this...

    Sheets(1).Select 'this selects the first sheet.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: how to reference sheets properly?

    That would be:
    Please Login or Register  to view this content.

    Just a tip, there should be virtually no reason to "select" a sheet before doing something to it, and it slows your code down to a crawl. The macro recorder leads people to do that because people DO select sheets before acting on them, so the recorder records you doing that. But in VBA, it's not necessary, actually bad to do.

    If you post more of your code we can assist you passing instructions directly to a worksheet withOUT selecting it first.
    Last edited by JBeaucaire; 05-25-2010 at 01:30 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: how to reference sheets properly?

    You can use
    Please Login or Register  to view this content.
    - Where Sheet1 is the name of the worksheet in the Project explorer rather than the name on the tab.

    Is that what you are asking?

  5. #5
    Registered User
    Join Date
    05-03-2010
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: how to reference sheets properly?

    Sheets("Sheet1").Select
    ActiveSheet.Range("$A$1:$E$13513").AutoFilter Field:=1, Criteria1:="mol/l"
    that is my 2nd line of code. is there a way to switch the activesheet.range into selecting the correct sheet all in one line?

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: how to reference sheets properly?

    Yep:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1