Msgbox Vbokcancel help

Kemidan2014

Board Regular
Joined
Apr 4, 2022
Messages
229
Office Version
  1. 365
Platform
  1. Windows
I wanted to set up a simple reminder message box at the start of a macro to ask if the user updated a specific file and basically OK iand continue he macro or Stop the macro if they hit cancel
I googled Msgboxs for vbokCancel types but i dont get a real clear examples on how to exectue them just explanations on the options for message boxes

is it really as simple as i just need "MsgBox ("Did you Remember to update ToyotaDefect.xlsx?"), vbOKCancel" ? I feel like theres a requirement to assign what OK button does and the Cancel button does.

VBA Code:
Sub Defect()
'Do not run with out toyota defect open
Dim Resp As String
MsgBox ("Did you Remember to update ToyotaDefect.xlsx?"), vbOKCancel
If Resp = vbCancel Then
Exit Sub
Else: Resume Next
End If


Sheets("Complaints").Unprotect Password:="Secret"
Application.ScreenUpdating = False
Workbooks.Open ("O:\1_All Customers\Current Complaints\ToyotaDefect.xlsx")

Dim LastRow As Long, fromsh As Worksheet, tosh As Worksheet, lastrowb As Long
Set fromsh = Workbooks("ToyotaDefect.xlsx").Sheets("Data")
Set tosh = Workbooks("Customer Complaint Tracker.xlsm").Sheets("Complaints")
 LastRow = fromsh.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    lastrowb = tosh.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

With tosh
  .Range("AX2:AX" & lastrowb).Formula = "=SUMIF([ToyotaDefect.xlsx]Data!$A:$A,A2,[ToyotaDefect.xlsx]Data!$AC:$AD)"
  .Range("AX2:AX" & lastrowb).SpecialCells(xlCellTypeVisible).Copy
  .Range("AI2").PasteSpecial xlPasteValues
End With
Sheets("Complaints").Protect Password:="Secret"
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Maybe a vbYesNO will work for you. If the user clicks "No", the macro will not execute..
VBA Code:
Sub Defect()
    'Do not run with out toyota defect open
    If MsgBox("Did you Remember to update ToyotaDefect.xlsx?", vbYesNo) = vbNo Then Exit Sub
    Application.ScreenUpdating = False
    Sheets("Complaints").Unprotect Password:="Secret"
    Application.ScreenUpdating = False
    Workbooks.Open ("O:\1_All Customers\Current Complaints\ToyotaDefect.xlsx")
    Dim LastRow As Long, fromsh As Worksheet, tosh As Worksheet, lastrowb As Long
    Set fromsh = Workbooks("ToyotaDefect.xlsx").Sheets("Data")
    Set tosh = Workbooks("Customer Complaint Tracker.xlsm").Sheets("Complaints")
    LastRow = fromsh.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    lastrowb = tosh.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With tosh
      .Range("AX2:AX" & lastrowb).Formula = "=SUMIF([ToyotaDefect.xlsx]Data!$A:$A,A2,[ToyotaDefect.xlsx]Data!$AC:$AD)"
      .Range("AX2:AX" & lastrowb).SpecialCells(xlCellTypeVisible).Copy
      .Range("AI2").PasteSpecial xlPasteValues
    End With
    Sheets("Complaints").Protect Password:="Secret"
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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