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:

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
18,125
Office Version
2013
Platform
Windows
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
 

IAIPICI

New Member
Joined
Nov 16, 2010
Messages
25
Can't belive I didn't try that before!lol. Thanks very much mate, works fine now.:biggrin:
 

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,773
What's vbcaution? Do you mean vbQuestion or vbExclamation?
 

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,773
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.
 

Forum statistics

Threads
1,081,415
Messages
5,358,533
Members
400,502
Latest member
price83

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top