macros errors

N

Natalie

Hi,

I am creating a spreadsheet for different people to look at, and I have
added a macro button to change the view for each group of people.

However, if it is already on the view they want, and they press it again, it
is coming up with an error. Is there anyway I can get the error to not come
up, and just ignore it that the button has been pressed?
 
B

Bob Phillips

Can we see the code, and where it errors?

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
N

Natalie

It is showing Runtime error 1004.

The macro hides 5 worksheets, and if the sheets are already hidden, and the
button is pressed again this is the error that appears.
 
B

Bob Phillips

Natalie,

I think you are going to have to show us the code. I entered this in the
immediate window

worksheets("Sheet1").visible = false

ran it multiple times, no problem, as I expected. No problem if I changed
False to xlSheetHidden or even xlSheetVeryHidden.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
P

PeterAtherton

Try something like this:

Sub test()
If Worksheets("Sheet1").Visible = False Then
Worksheets("Sheet1").Visible = True
Else: Worksheets("Sheet1").Visible = False
End If
End Sub

Peter
 
D

Dave Peterson

Make sure you always have at least one visible sheet.

(maybe you're trying to hide the last visible sheet.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top