+ Reply to Thread
Results 1 to 5 of 5

Use variable in worksheet name

  1. #1
    Registered User
    Join Date
    09-18-2009
    Location
    Grand Forks, North Dakota
    MS-Off Ver
    Excel 2007
    Posts
    41

    Wink Use variable in worksheet name

    Hello,

    I have the following code and keep getting an runtime error 9 Subscript our of range error. I've tried using the codename and the sheet name. Neither seems to work though. I've tested the variable and it does show the correct sheet name and I've tried other sheet names also. If I hard code in the sheet name it works fine. For some reason I cannot get the value of the variable to work within the Sheets object parenthesis.


    Please Login or Register  to view this content.
    Last edited by ndjustin20; 01-09-2020 at 05:22 PM.

  2. #2
    Registered User
    Join Date
    09-18-2009
    Location
    Grand Forks, North Dakota
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Use variable in worksheet name

    I finally got it. The ActiveX dropdown returns a string already. I was trying to convert a string to a string and it was actually leaving it as an integer then as originally declared to begin with. I hope that isn't as confusing as it sounds I wish the compiler would have just thrown a type mismatch error when I tried to use CStr on the string I was getting from the dropdown.



    Thanks again!!

  3. #3
    Registered User
    Join Date
    01-08-2020
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    2010
    Posts
    9

    Re: Macro not work in shared workbook

    Hello Mr. Ndjustin20, I have the following code to make hide & unhide shape. It working perfectly but when this worksheet to make 'share' then it not working. Plz help me..

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by moktr; 01-10-2020 at 09:15 AM. Reason: tag missing

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Use variable in worksheet name

    Hi moktr,

    Two things! First, please use code tags when posting code, and second, if you have a question please post your question in your own thread.
    HTH
    Regards, Jeff

  5. #5
    Registered User
    Join Date
    01-08-2020
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    2010
    Posts
    9

    Re: Use variable in worksheet name

    Hi Mr. thanks for reply. My main problem is, this macro not work in shared workbook.

+ 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. Replies: 10
    Last Post: 09-10-2018, 06:58 PM
  2. [SOLVED] Save the name of a Worksheet into a variable and then use that variable as worksheet name
    By IonutC in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-28-2016, 07:07 AM
  3. [SOLVED] Worksheet: Object variable or With block variable not set?
    By Greg J. in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-28-2013, 12:03 PM
  4. [SOLVED] Replacing a referenced worksheet name with a variable worksheet index number.
    By sdavison in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-01-2013, 09:49 AM
  5. [SOLVED] TypeName limitation: How to distinguish Worksheet Variable from Workbook variable
    By bagullo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-02-2013, 07:35 AM
  6. Replies: 1
    Last Post: 09-07-2012, 12:08 AM
  7. [SOLVED] Store variable in worksheet and use that variable in VBA code
    By ExcelGal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2012, 08:20 AM

Tags for this Thread

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