Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Runtime error 1004 - Application defined error

Posted on 2013-12-03
12
Medium Priority
?
388 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 35

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 35

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 35

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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
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…

916 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