Solved

Runtime error 1004 - Application defined error

Posted on 2013-12-03
12
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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 34

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 34

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 34

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel Web Add-in Where is Visual Basic used 9 85
Excel Auto-Complete lines 4 32
Userform to show a range in excel. 3 34
can you help get  64bit version of these 3 APIs? 4 35
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
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…

752 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