MsgBox vbYesNo

hillmas83

New Member
Joined
Aug 23, 2017
Messages
6
Hi,

I am trying to write some vba code which will allow me to look to see the value of a cell, if that cell = X then display a msgbox "cell = X, are you Sure?" with options yes or no. If they click no then it exits the sub routine. If they click yes then the code continues onto the next line.

i am quite sure i being stupid but just cant figure it out.

so far i have the below but it doesnt like it for some reason and just crashes my excel when i run it...

Code:
If Sheets("Data 2").Range("I7") <> "N" Then
   If MsgBox("This line has already been submitted with the below details..." & vbNewLine & vbNewLine & ("Do you want to override the data?") & vbNewLine & vbNewLine & Range("H8") & Dup_Added_By & vbNewLine & Range("H9") & Dup_Block_Type & vbNewLine & Range("H10") & Dup_Apply_Date & vbNewLine & Range("H11") & Dup_End_Date, vbYesNo + vbQuestion) = vbNo Then Exit Sub
Else


End If
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try:
Code:
    Dim s   As String
    
    s = "This line has already been submitted with the details below:@NL@NLDo you wish to override the data?@NL@NL"
    s = s & Cells(8, 8).Value & Dup_Added_By & "@NL"
    s = s & Cells(9, 8).Value & Dup_Block_Type & "@NL"
    s = s & Cells(10, 8).Value & Dup_Apply_Date & "@NL"
    s = s & Cells(11, 8).Value & Dup_End_Date & "@NL"
    
    If sheets("Data 2").Cells(7, 9).Value <> "N" Then
        If MsgBox(Replace(s, "@NL", vbCrLf), vbYesNo, "Replace Data?") = vbNo Then Exit Sub
    Else
    
    End If
 
Upvote 0
I have no problems with your code.
It can also be like this:

Code:
  If Sheets("Data 2").Range("I7") <> "N" Then
    If [COLOR=#0000ff]MsgBox("This line has already been submitted with the below details..." & vbCr & vbCr & _[/COLOR]
      ("[COLOR=#008000]Do you want to override the data?") & vbCr & vbCr & _[/COLOR]
[COLOR=#008000]        Range("H8") & Dup_Added_By & vbCr & _[/COLOR]
[COLOR=#008000]        Range("H9") & Dup_Block_Type & vbCr & _[/COLOR]
[COLOR=#008000]        Range("H10") & Dup_Apply_Date & vbCr & _[/COLOR]
[COLOR=#008000]        Range("H11") & Dup_End_Date, vbYesNo + vbQuestion[/COLOR]) [COLOR=#0000ff]= vbNo Then Exit Sub[/COLOR]
  Else
  End If
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,047
Members
448,940
Latest member
mdusw

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