VBA MsgBox based on rows - continue if true cancel if false

sycodiz

New Member
Joined
Jun 15, 2008
Messages
27
I have searched everywhere for this answer. I am sure it is out there but I feel like I am going in circles. So I came here to you awesome people for help and direction!
I do apologize that I am not very savvy in VBA but occasionally I do have to create some crude macros and then come to you great folks for advice.

I have a macro created that will grab data and move to another sheet and then save off. I even have some validations. Everything works great.
However, I am trying to do a validation on some cells. If the cell is false, I would like a msgbox to say "Row x has an error, do you wish to accept and continue?" if the answer is yes, the code moves on. If the answer is no, then I would like a response "Please fix row x" and then exit the sub.

The values are in f38:f64. They are a value of true or false.

I have wrote each line out but I am having issues with the exiting sub. It keeps returning the same second message no matter if I choose yes or no.
This is where I am at the code right now.

If Range("f38").Value = False Then
MsgBox "Row 38 has an error, do you whish to accept and continue?", vbYesNo + vbQuestion, "Error found"

If VbMsgBoxResult.vbYes Then MsgBox "Please fix row 38"

Else
Exit Sub
End If

I can have each line in the code if needed, I think there is a way to do a loop and return the line that finds the value of false.

Any help would be greatly appreciated.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
do you want to check all those cells in the range with one macro. if yes then this should be something like what you need i hope.
VBA Code:
Sub CheckRange()
    Dim Row As Long
    
    For Row = 38 To 64
        If Cells(Row, 6).Value = False Then
            MsgBox "Row " & Row & " has an error, do you wish to accept and continue?", vbYesNo + vbQuestion, "Error found"
            If VbMsgBoxResult = vbNo Then
                MsgBox "Please fix row " & Row & " now. You should run this check again after correction"
            End If
        End If
    Next Row
End Sub
 
Upvote 0
do you want to check all those cells in the range with one macro. if yes then this should be something like what you need i hope.
VBA Code:
Sub CheckRange()
    Dim Row As Long
   
    For Row = 38 To 64
        If Cells(Row, 6).Value = False Then
            MsgBox "Row " & Row & " has an error, do you wish to accept and continue?", vbYesNo + vbQuestion, "Error found"
            If VbMsgBoxResult = vbNo Then
                MsgBox "Please fix row " & Row & " now. You should run this check again after correction"
            End If
        End If
    Next Row
End Sub
Works great, except no matter if I choose Yes or No, the second msgbox pops up. It should only pop up if the answer yes. Thanks for your quick reply.
 
Upvote 0
corrections :)
VBA Code:
Sub CheckRange()
    Dim Row As Long
    
    For Row = 38 To 64
        If Cells(Row, 6).Value = False Then
            Res = MsgBox("Row " & Row & " has an error, do you wish to accept and continue?", vbYesNo + vbQuestion, "Error found")
            If Res = vbNo Then
                MsgBox "Please fix row " & Row & " now. You should run this check again after correction"
            End If
        End If
    Next Row
End Sub
 
Upvote 0
haha. you're welcome. come back if you need to sort anything else
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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