+ Reply to Thread
Results 1 to 9 of 9

VBA to hide sheet in workbook and also reference in code

  1. #1
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    VBA to hide sheet in workbook and also reference in code

    Hello:

    I am trying to Hide certain data and calculation sheets in a workbook but still reference it in my code and macro buttons on other sheets. Is there a way to do this?

    Thanks

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,899

    Re: VBA to hide sheet in workbook and also reference in code

    Do you need to hide the sheets using code?

    Please Login or Register  to view this content.
    There is no difference in the code between referring to a visible sheet vs. referring to a hidden sheet.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: VBA to hide sheet in workbook and also reference in code

    Thanks. When I tried entering the code

    Worksheets("Data").Visible = False

    there seems to be an error and it keeps highlighting the following line

    Sheets("Data").Select

    Thanks

  4. #4
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Pakistan
    MS-Off Ver
    Excel 2013
    Posts
    256

    Re: VBA to hide sheet in workbook and also reference in code

    Try the below code:
    This code paste on the worksheet which you want to hide.. When a user click to unhidden the sheet the password prompt appears if user provide the correct password then the worksheet ( Data) will be visible other wise re hidden. For this code you have set the password on vba project too to protect the viewing of worksheet code.
    Please Login or Register  to view this content.
    Thanks
    farrukh

  5. #5
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: VBA to hide sheet in workbook and also reference in code

    Thanks. That is good to have. Is there a code to just hide the Data sheet and still use in my code. I am trying to remove some tabs that are not necessary for a user but still use it in code. When I paste the following in my code i am getting an error message:

    Worksheets("Data").Visible = False

    and it is highlighting the following:

    Sheets("Data").Select

    thanks

  6. #6
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: VBA to hide sheet in workbook and also reference in code

    Quote Originally Posted by rlsublime View Post
    Sheets("Data").Select
    just delete it!
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  7. #7
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Re: VBA to hide sheet in workbook and also reference in code

    Deleting it is not an option since I am referencing that sheet in other code. I just want to hide the sheet in the workbook and still refer to it in the code.

  8. #8
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: VBA to hide sheet in workbook and also reference in code

    just try it according to the provided code
    Please Login or Register  to view this content.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,899

    Re: VBA to hide sheet in workbook and also reference in code

    Quote Originally Posted by rlsublime View Post
    Deleting it is not an option since I am referencing that sheet in other code. I just want to hide the sheet in the workbook and still refer to it in the code.
    You do not need to select a worksheet to refer to it in your code. In fact, it is an undesirable practice in VBA. You have never posted your code for this problem, that might help us figure out what you really want to do.

+ 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