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
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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
 
Upvote 0
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
 
Upvote 0
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...
 
Upvote 0
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.
 
Upvote 0
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???
 
Upvote 0
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
 
Upvote 0
kpark91, thank you for your assistance today. It worked. Thank you so much!!!

Pedie:)
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,755
Members
448,989
Latest member
mariah3

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