VbyesNO....need more help. Add few more line..Thanks

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
My current code looks like this...
I just want someone to please add one more condition to it...

If sheet1.Range("d5").Value = "Stop" then same as below..
or
If sheet1.Range("d5").Value = "" then
msgbox "it is empty...."
exit sub
' Stop the code from running any more
Otherwise my code...



Code:
Sub try1()
Dim Responce As VbMsgBoxResult
If sheet1.Range("d5").Value = "Stop" Then
Responce = MsgBox("my message....?", vbYesNo, "Question")
Else
GoTo skip:
End If
If Responce = vbYes Then
skip:
' code
Else
End If
End Sub
 

kpark91

Well-known Member
Joined
Jul 15, 2010
Messages
1,582
Code:
Sub try1()
Dim Responce As VbMsgBoxResult
If sheet1.Range("d5").Value = "Stop" Then
Responce = MsgBox("my message....?", vbYesNo, "Question")
ElseIf Sheet1.Range("d5").Value = vbNullString Then
MsgBox ("It is empty...")
Else
GoTo skip
End If
If Responce = vbYes Then
skip:
' code
Else
' code
End If
End Sub
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,362
Office Version
365
Platform
Windows
You could try Select Case.

Code:
Option Explicit
 
Sub try1()
Dim Response As VbMsgBoxResult
 
    Select Case Sheet1.Range("d5").Value
    
        Case "Stop"
            
            Response = MsgBox("my message....?", vbYesNo, "Question")
        
        Case ""
            Response = MsgBox("my message....?", vbYesNo, "Question")
            
        ' add other cases if required
        
        Case Else
            ' do nothing
    End Select
    
    ' do other things based on response
    
End Sub
 

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Thank you so much for helping....:)
Now the code is giving error If there is some other value in instead of "Stop" in D5. error runtime error 13, type mismtach...

Lemmi try the Case case of Norie...
 

kpark91

Well-known Member
Joined
Jul 15, 2010
Messages
1,582
pedie.
The error might be happening because of your process (skip).

Do you want to access your process (skip) only when the user have answered yes?

Then you should delete GoTo skip in else statement.
 

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
kpark91, it is working now. I was doing it wrong.
But just one more question...

Can we put a condition for range("D1:D5") instead of D5 only???
 

kpark91

Well-known Member
Joined
Jul 15, 2010
Messages
1,582
Code:
Sub try1()
Dim Responce As VbMsgBoxResult
For c = 1 To 5
    If sheet1.Range("d" & c).Value = "Stop" Then
        Responce = MsgBox("my message....?", vbYesNo, "Question")
    ElseIf Sheet1.Range("d" & c).Value = vbNullString Then
        MsgBox ("It is empty...")
    End If
Next c
    If Responce = vbYes Then
    skip:
        ' code
    Else
        ' code
    End If
End Sub
 

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
kpark91, thank you for your assistance today. It worked. Thank you so much!!!

Pedie:)
 

Forum statistics

Threads
1,082,257
Messages
5,364,074
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