populate message box from the second running the macro

Mussa

Active Member
Joined
Jul 12, 2021
Messages
264
Office Version
  1. 2019
  2. 2010
Hi
I have procedure to populate message box before the run my macro
VBA Code:
ans = MsgBox("are you sure you want to continue ?", vbYesNo)
If ans = vbNo Then Exit Sub
'my macro
'
'
what I want the message box should show from the second running when click the button for my macro , not from the first time click the button , is it possible , guys?
 
That is what you asked for!! if you delete cell A1 in between running the macro first time and second time you will see that it does fill A1 both times
when run the macro from the first time then will fill in A1 cell directly aA and when run again will show messgagebox if I click yes will fill in A1=aA and if I click no will not fill in A1 cell
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
if you delete cell A1 in between running the macro first time and second time
no no !
I'm talking about when fill from first time will fill and before run the second time will A1= aA I don't delete it , then the code should show message to give as long the A1 is filling to permission go running code or not.
 
Upvote 0
well , this is my last try
in pic1 when run from the first time
AZ1.PNG


and when run again every time will show message
az2.PNG

and complete the procedure if I clicl yes or no as I said before.
 
Upvote 0
try this;
VBA Code:
Public firstrun as Boolean
Sub test2()

If firstrun Then
    Range("a1").Value = "Aa"
    ans = MsgBox("are you sure you want to continue ?", vbYesNo)
    If ans = vbNo Then Exit Sub
    firstrun = True
Else
    Range("a1").Value = "aA"
    firstrun = True
End If

End Sub
 
Last edited:
Upvote 0
thanks
but now I'm so confused !
I suppose your code will populate aA from the first time and this is ok ,but when run again should keep aA whether I click no or close the message without click yes , but I see to change to Aa whethere click yes or no !!
 
Upvote 0
If you look at your two picures you have got aA after the first run and Aa after the second run that is exactly what the code does!! It took me a while to spot that you changed aA to Aa but I presumed that is what you wanted!!
 
Upvote 0
code will populate aA from the first time and this is ok ,but when run again should keep aA whether I click no or close the message without click yes

Hi,
not sure fully understood this thread but see if this update to your code does what you want

VBA Code:
Sub Mussa()
   Dim ans As VbMsgBoxResult

    With Range("A1")
        'check for first run
        If Val(.ID) = xlFirst Then
            .Value = "aA"
            .ID = xlDialogDisplay
        Else
            'display msgbox
            ans = MsgBox("are you sure you want To continue ?", vbYesNo)
            If ans = vbNo Then Exit Sub
           
            'update range
            .Value = "Aa"
           
        End If
    End With
   
    'rest of code
   
End Sub

Dave
 
Upvote 0
Hi Dave ,
seem the same offthelip's solution !
ok guys I meant this line
.range("a1").value= "aA" just I gave example what macro should do .
my goal if i run the first time then will call my macro , also if run again then will show message and if I click ok should call my macro , but if I click no then should not call my macro .
instead of .range("a1").value= "aA" should be call my macro
ok I will try to adapt your codes and how goes
thanks guys.
 
Upvote 0
Use the code I posted in post #7 and put your macro code where it says "my macro"
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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