Logical validation macro

rhino4eva

Active Member
Joined
Apr 1, 2009
Messages
262
Office Version
  1. 2010
Platform
  1. Windows
I have a spread sheet that has 3 columns by 96 rows i need a vba macro to check data validity. i would normally be able to sort it out but i am unsure how to implement an "and" & "or" in the logic

a b c
1 123 x x ok
2 124 x ok
3 125 bad
4 x bad
5 x x bad
etc

i need to scan from row 1 to row 96 if there is an entry in column "a" there must be entries in "b" or "c" but if no entry in "a" there should not be in "b" or "c" .
the validation outcome could be reported by a msgbox
if anyone has any ideas i would be really grateful
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Assuming you are working will columns A-C and Rows 1-96 (if not, adjust accordingly), this should work.
Code:
Sub MyValidation()
 
    Dim i As Integer
    
    For i = 1 To 96
'   What to do if value in column A...
        If Len(Cells(i, "A")) > 0 Then
'   Check for entries in columns B or C
            If Len(Cells(i, "B")) = 0 And Len(Cells(i, "C")) = 0 Then
                MsgBox "Bad entry in row " & i
            End If
'   What to do if column A blank
        Else
            If Len(Cells(i, "B")) > 0 Or Len(Cells(i, "C")) > 0 Then
                MsgBox "Bad entry in row " & i
            End If
        End If
    Next i
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,865
Members
452,948
Latest member
UsmanAli786

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