+ Reply to Thread
Results 1 to 5 of 5

Using Variable to call Worksheet

  1. #1
    Registered User
    Join Date
    08-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Smile Using Variable to call Worksheet


    Hi all! I am new to this forum and I am very excited about all of the talent that I see here. It has been years since I have coded and now I am just starting again. I am trying to use a vlookup to find the name of a worksheet that I want to call. I have the lookup working as I have a msgbox that shows me the name of the worksheet is stored in the variable, but for some reason it will not allow me to select the sheet so that I can run the rest of the macro. The very bottom line is where I keep striking out. I have looked at so many posts and tried so many different variations that I am now really confused. Any help you can give me would be greatly appreciated.

    Please Login or Register  to view this content.
    Thanks in advance for your miraculous (all be it easy for you) answer!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,243

    Re: Using Variable to call Worksheet

    You've defined Select_sht as a Workbook.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    08-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Using Variable to call Worksheet

    I have tried multiple defining it as a multitude of things. Can someone tell me what I should define it as so that this will work?

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Using Variable to call Worksheet

    The variable Select_Sht should be data type Worksheet.

    Then, after your code, the line
    Please Login or Register  to view this content.
    will select that sheet.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    08-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Using Variable to call Worksheet

    Hi Mikerickson. I thought about what you said after I read your first post and changed it to worksheet. I also had added the Select_Sht.Activate before reading your last post. You have been a tremendous amount of help. I really appreciate it! It works great now. Thank you!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,243

    Re: Using Variable to call Worksheet

    Not wishing to be picky, but the first response was mine. Maybe I was being too subtle, but I thought it might click that if you were trying to access a worksheet, defining the variable as a workbook might just cause a problem.

    Regards, TMS

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Call a constant/variable by creating another variable
    By pienaaj in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-12-2013, 10:36 AM
  2. Variable in referenced worksheet call
    By hektisk in forum Excel General
    Replies: 9
    Last Post: 04-06-2011, 07:00 PM
  3. Call variable from String
    By juancamilo87 in forum Access Programming / VBA / Macros
    Replies: 4
    Last Post: 02-03-2011, 01:03 AM
  4. Variable procedure call
    By Art in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-16-2005, 09:20 AM
  5. Define worksheet as variable, then call in macro
    By bugman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2005, 01:20 PM

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