Adding a prompt box before executing a macro

Harry_T

New Member
Joined
Sep 27, 2017
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I have a macro that I know works that would copy data from a range on one sheet within the workbook and paste the data as values in the desired location.

Macro:
Sheets("Master_Listing").Select
Range("B2:B349").Select
Selection.Copy
Sheets("Busy Season Tracker").Select
Range("B3:b350").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub

I tried to look up VBA on the forum and tried two different VBA strings but seem to keep getting a debug error with both strings of VBA code. When hitting debug, it takes me to the VBA code that is referencing the range that the macro is trying to copy the data from...Range("B2:B349").Select from worksheet "Master_Listing"

#1:

Dim Msg As String, Ans As Variant


Msg = "Would you like to update the listing?"


Ans = MsgBox(Msg, vbYesNo)


Select Case Ans


Case vbYes

**** The VBA from the Macro ****

Case vbNo
GoTo Quit:
End Select


Quit:

#2



Dim reply
reply = MsgBox("Do you want to proceed.?", vbYesNo)
If reply = vbNo Then Exit Sub

**** The VBA from the Macro ****


Is there something that I'm doing wrong here? Thanks for your help in advance!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi Harry_T,

Try this:

Code:
Option Explicit
Sub Macro3()
    
    If MsgBox("Would you like to update the listing?", vbQuestion + vbYesNo) = vbYes Then
        Application.ScreenUpdating = False
        Sheets("Master_Listing").Range("B2:B349").Copy
        Sheets("Busy Season Tracker").Range("B3:B350").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        With Application
            .CutCopyMode = False
            .ScreenUpdating = True
        End With
    End If
 
End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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