Solved

Runtime error 1004 - Application defined error

Posted on 2013-12-03
12
379 Views
Last Modified: 2013-12-10
I am getting and Runtime error 1004 - Application defined error after the Else statement below.  Sheet8 is hidden and it is suppose to Unhide the sheet.

Public Function GoMenu(Optional Awhere As String) As Boolean
GoMenu = False
If Awhere = "" Then
    Sheet01.Select
    Sheet01.Range("StatRoll").Select
Else
  If ActiveWorkbook.Worksheets(Awhere).Visible = xlHidden Then ActiveWorkbook.Worksheets(Awhere).Visible = True
   ActiveWorkbook.Worksheets(Awhere).Select
   ActiveWorkbook.Worksheets(Awhere).Activate
   ActiveWorkbook.Worksheets(Awhere).Range("B3").Select
End If
GoMenu = True
End Function
0
Comment
Question by:leezac
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 39693584
Are you sure that there is a sheet named with the passed string?
You have to make sure to pass the sheet's tab name, not the code name.

Thomas
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39693613
And the spelling should be an exact match. Any leading, trailing or extra space would make it fail.
0
 

Author Comment

by:leezac
ID: 39693621
When I click F4 to view the properties

(Name) is Sheet08
and Name is Maintenace

When I try to select the dropdown manually to unhide for the Visible property - I get "Unable to set the Visible property of the Worksheet class"   error message
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 39

Expert Comment

by:nutsch
ID: 39693627
So the AWhere string should be set to Maintenace, not Sheet08, is that what you have?
0
 

Author Comment

by:leezac
ID: 39693683
Public Function GoMenu(Optional Awhere As String) As Boolean


awhere = maintenance when I highlight the above line.

I did not write this code - am just trying to fix
0
 
LVL 33

Expert Comment

by:Norie
ID: 39693708
Does this work?
With ActiveWorkbook.Worksheets(Awhere)
     .Visible = True
     Application.Goto .Range("B3")
End With

Open in new window

0
 

Author Comment

by:leezac
ID: 39693748
imnorie - I think should work but does not.  

And when I manually try to change it properties window --
When I try to select the dropdown manually to unhide for the Visible property - I get "Unable to set the Visible property of the Worksheet class"   error message

This happens to me on occasion and I can't remember what I do to fix.
0
 
LVL 33

Expert Comment

by:Norie
ID: 39693760
Is the sheet/workbook protected?
0
 

Author Comment

by:leezac
ID: 39693988
I had the person using the file open a prior one and it works so just may use it.  Seems like a bug.   The file was working fine with same code for a while.  This just happened.
0
 
LVL 33

Expert Comment

by:Norie
ID: 39694096
Are there any other workbooks open when you get the error?
0
 

Author Comment

by:leezac
ID: 39694112
No - I closed the other workbooks.
0
 
LVL 4

Accepted Solution

by:
andrew_man earned 500 total points
ID: 39694218
Public Function GoMenu(Optional Awhere As String) As Boolean
GoMenu = False
If Awhere = "" Then
    Sheet01.Select
    Sheet01.Range("StatRoll").Select
Else
  If ActiveWorkbook.Worksheets(Awhere).Visible = xlHidden Then ActiveWorkbook.Worksheets(Awhere).Visible = True
   ActiveWorkbook.Worksheets(Awhere).Select
   ActiveWorkbook.Worksheets(Awhere).Activate
   ActiveWorkbook.Worksheets(Awhere).Range("B3").Select
End If
End If
GoMenu = True
End Function
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question