+ Reply to Thread
Results 1 to 3 of 3

Run-Time Error '1004': Method 'Visible' of Object'_Worksheet' Failed

  1. #1
    Registered User
    Join Date
    03-07-2015
    Location
    pigeon forge tn
    MS-Off Ver
    2010
    Posts
    14

    Run-Time Error '1004': Method 'Visible' of Object'_Worksheet' Failed

    I am getting this error code: ""Run-Time Error '1004': Method 'Visible' of Object'_Worksheet' Failed""

    When trying to run this code:

    Sub SheetDate()

    Dim ws As Worksheet
    Dim oName As Variant

    oName = Format(Date, "mm-dd-yy")
    For Each ws In Worksheets
    If Not ws.Name = oName Then ws.Visible = xlSheetHidden
    Next ws
    End Sub


    What I am trying to do is have a command button open certain sheets by date. This works but gives me that error code.

    And is there a way i can open different sheets by the same date.

    I have:
    E21 03-14-2015
    E22 03-14-2015
    E27 03-14-2015

    I need to be able to open each one with a different button.

  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
    37,295

    Re: Run-Time Error '1004': Method 'Visible' of Object'_Worksheet' Failed

    Please Login or Register  to view this content.

    Works for me. Note that oName should be a string rather than a variant; variant is very inefficient and should be avoided where possible. You must have at least one sheet visible and a sheet name must be unique so, if there isn't a sheet with the current date, it will try to hide everything and fail on the last worksheet, whatever that happens to be.


    Regards, TMS

  3. #3
    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
    37,295

    Re: Run-Time Error '1004': Method 'Visible' of Object'_Worksheet' Failed

    Please note ...

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

+ 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. run-time error '1004' method 'range' of object '_worksheet' failed
    By Emma_B in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-26-2014, 09:00 AM
  2. [SOLVED] How can I resolve this Run-Time error '1004': Method 'Range' of object '_Worksheet' failed
    By dafella in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2013, 01:16 AM
  3. [SOLVED] Run-time error '1004': Method 'Select' of object'_Worksheet' failed
    By vbiggs101 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-07-2013, 02:56 PM
  4. Run time Error 1004 Method 'Range' object '_Worksheet 'failed
    By Monica1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2013, 07:42 AM
  5. me too - run-time error '1004' method 'range' of object '_worksheet' failed
    By ASAFSWIS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-07-2013, 05:14 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