Button to MsgBox help plz!

IAIPICI

New Member
Joined
Nov 16, 2010
Messages
25
Hey,

I have designed a button to run a macro which deletes old information when pressed. I wanted to have a vbYesNo MsgBox popup to ask the user if the are sure they wish to delete data. This macro seems to work fine and completes its task but once it is finished I am getting "Object Required" Error.

my code is below:
________________________________________________________
Sub DeleteButton()
Dim Question As Byte, Type1 As Integer
Type1 = vbYesNo + vbcaution + vbDefaultButton2
Question = MsgBox("Are you sure you want to delete the current information from this spreadsheet?", Type1)

If Question = vbYes Then Macro1

If button6.Click Then 'Question'

End If
End Sub
________________________________________________________

As said above the code seems to work fine but I am getting the object required error anyway.

Could someone please tell me what I am doing wrong?:confused:

Thanks,

Andrew
 
Last edited:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I may be misunderstanding but try
Code:
Sub DeleteButton()
Dim Question As Byte, Type1 As Integer
Type1 = vbYesNo + vbcaution + vbDefaultButton2
Question = MsgBox("Are you sure you want to delete the current information from this spreadsheet?", Type1)
If Question = vbYes Then Macro1
End Sub
 
Upvote 0
What's vbcaution? Do you mean vbQuestion or vbExclamation?
 
Upvote 0
May I suggest that you place the Option Explicit directive at the top of all your code modules in future?

If you do this, VBA will point out any typos of this nature before you get as far as trying to run the code.

Example: imagine if you were looping through some cells aggregating their value in a variable called intTotal and then later you wanted to use the value in that variable and accidentally typed inTotal. It would contain zero and you'd be wondering why. Option Explicit prevents that from happening.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top