Command Button Problem

A

albertmb

Hi everyone, can you please help me on this problem.

I have a multi sheet document and not to create confusion I hid all sheets
and assigned a command button to each sheet to unhide. All worked fine up to
Button 9, but when it came to button 10 I got this error:

"Ambiguos name detected: CommandButton10_Click()".

The Sub is as follows:

Private Sub CommandButton10_Click()
Sheets("Cost Lm").Visible = True
Sheets("Cost Lm").Select
End Sub

Thank You
Albert
 
M

Mike H

Hi,

This error would be generated if you had 2 subroutines with the same name so
check carefully that they are all different. There's nothing wrong with the
code in the sub you posted.

Mike
 
M

Mike H

Hi,

I should have added that you can't hide all sheets in a workbook you must
leave at least one sheet visible and I assume you are doing this with the
sheet that has these buttons on.

Mike
 
A

albertmb

Thank You for answering Mike. I have looked at all the subs very carefully
but I have no double entries. Is it possible that I reached the limit for
entering subs?
 
M

Mike H

Hi,

No the number of sub's isn't a problem and I,m still of the view that the
problem is a duplicate sub.

Try this. In a brand new and empty workbook put 2 command buttons on a
worksheet and right click the first and view code and enter this

Private Sub CommandButton1_Click()
MsgBox "Hello"
End Sub

go back to the worksheet and right click the second and view code and you
should see this

Private Sub CommandButton2_Click()

End Sub

change the 2 to a 1 so the code is identical to the first
Go back to the worksheet and click Button 1 and you will get

Compile error:

Ambiguous name detected: CommandButton1_Click

Is this the same error you are getting?

Mike
 
A

albertmb

Thanks once again Mike. I tryed them all but still same error. I even tryed
inserting new command buttons but still same error is comming up. I can
assure there are no double entries. It's my first time using command buttons
so I had to make sure I was doing nothing wrong. The only difference I could
see was that up to Button 7
I was getting this :
Private Sub CommandButton9_Click()

End Sub
by default, from button 8 I had to wright it myself.

Thanks
Albert
 
A

albertmb

Hi Mike it's me again, Thank you for your interest, actually you were right,
in my last message I told you that the usual default items were not showing,
actually for some reason instead of following command button 9, the default
items followed command button 1, but cursor followed command button 9, so I
did not look further up.

Thanks once again

Albert
 

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