Pretty basic VBA help....if you know how!!

  • Thread starter Thread starter Big Chris
  • Start date Start date
B

Big Chris

Hello!

Thanks for taking the time to look at this help request. This is the
last bit to complete my first Excel project involving VBA!

I basically have a button which fires up a macro with a VBA input box
into which users are invited to enter an 8 digit code.
What I need to do is to say 'If the code entered is the same as the
number in Sheet1!A1 then delete the button. If it's not the same as
Sheet1!A1 then give a 'that is not the right code' message and stop.

Looking at what you guys are writing about I know this should be easy,
but I've not yet reached that place where it all starts to click
together and self generate. Any advice on books etc that will help me
get there?

Thanks again...I appreciate your help.
 
CommandButton from the Control Toolbox Toolbar

Private Sub CommandButton1_Click()
res = InputBox("Enter 8 Digit Number:")
If CLng(res) = Worksheets("Sheet1").Range("A1").Value Then
Application.OnTime Now, "Deletebutton"
Else
MsgBox "Number is incorrect"
End If
End Sub

Code above should go in the sheet module where the button is located.

In a general module put this code:
Sub DeleteButton()
Worksheets("sheet1") _
.OLEObjects("Commandbutton1").Delete
End Sub

Commandbutton should be named CommandButton1 - both the name property and
the OleObject name.

Of course if the workbook is not saved after the delete, the next time you
open it the button will be back.
 
Back
Top