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
 

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,334
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
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,884
Office Version
2007
Platform
Windows
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
 

Forum statistics

Threads
1,082,258
Messages
5,364,081
Members
400,778
Latest member
Canadian Sal

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top