+ Reply to Thread
Results 1 to 9 of 9

Command Button - Hide and Unhide Sheet VBA

  1. #1
    Registered User
    Join Date
    01-26-2012
    Location
    Eden Praire
    MS-Off Ver
    Excel 2007
    Posts
    8

    Command Button - Hide and Unhide Sheet VBA

    Hi all, I'm trying to create a macro that will hide a sheet and unhide a different sheet and select a cell in the unhidden sheet. I keep getting a run-time error of 1004.

    Private Sub CommandButton1_Click()

    Application.ScreenUpdating = False
    Sheets("SMT Selection Process").Visible = False
    Sheets("Employee_List").Visible = True
    Sheets("Employee_List").Select
    Range("A1").Select

    End Sub

    It doesn't like the "Range("A1").Select, I'm using Excel 2007.

    Thanks guys.

  2. #2
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Re: Command Button - Hide and Unhide Sheet VBA

    Welcome to the Forum!

    You cannot select cells or work with them if the worksheets are hidden. Sheets have to be visible to work with them. That is why you are using the "Application.ScreenUpdating = False"

    Caution: if you "Application.ScreenUpdating = False" make sure to always have "Application.ScreenUpdating = True" somewhere before you End Sub.

    Does this work?

    Please Login or Register  to view this content.
    Last edited by clemsoncooz; 01-26-2012 at 12:47 PM.

  3. #3
    Registered User
    Join Date
    01-26-2012
    Location
    Eden Praire
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Command Button - Hide and Unhide Sheet VBA

    Hey clemsoncooz,

    That did the trick! Thanks for the quick response!!!

    Thanks again,
    kimber20

  4. #4
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Re: Command Button - Hide and Unhide Sheet VBA

    No problem



    If you like any of my suggestions please click the (star) reputationicon in the left down corner of this post.
    If resolved - Mark a thread as 'solved' = please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  5. #5
    Registered User
    Join Date
    01-26-2012
    Location
    Eden Praire
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Command Button - Hide and Unhide Sheet VBA

    Hey clemsoncooz,

    I spoke too soon, it failed again with the same error and it doesn't like "Sheets("Employee_List").Range("A1").Select".

  6. #6
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Re: Command Button - Hide and Unhide Sheet VBA

    Can you post a sample document or the doc itself?

  7. #7
    Registered User
    Join Date
    01-26-2012
    Location
    Eden Praire
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Command Button - Hide and Unhide Sheet VBA

    How do I post the file, I don't see an option for that.

  8. #8
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Re: Command Button - Hide and Unhide Sheet VBA

    To attach a file to your post, you need to be using the main 'New Post' or 'New Thread' page and not 'Quick Reply'.
    To use the main 'New Post' page, click the 'Reply to Thread' button in the relevant thread.

    On that page, below the message box, you will find a button labelled ' Go Advanced.'

    Then click on 'Manage Attachments'.
    Clicking this button will open a new window for uploading attachments.

    You can upload an attachment either from your computer or from another URL by using the appropriate box on this page.
    Alternatively you can click the Attachment Icon to open this page.

    To upload a file from your computer, 'Add Files' button (TOP RIGHT). click the 'Select Files' button and locate the file.

    Select Done then Submit Reply.

  9. #9
    Registered User
    Join Date
    03-09-2014
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Command Button - Hide and Unhide Sheet VBA

    Great thanks
    work perfect

+ 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