vba nested if

jaik22

Board Regular
Joined
Sep 23, 2016
Messages
102
Hi,

I would like to make code that if column B and A values are in the CheckList sheet,
Column C,D,E values must be in CheckList sheet. However validating Column B and A works good, but C, D, E are not working correctly.

Does anyone have any idea on this?

Code:
Dim ValidateL As Long: ValidateL = Sheets("CheckList").Cells(Rows.Count, 1).End(xlUp).Row
For Each rngCell In ActiveSheet.Range("F13:F" & rowLast)
      If WorksheetFunction.CountIf(Sheets("CheckList").Range("B2:B" & ValidateL), rngCell) <> 0 And _
      WorksheetFunction.CountIf(Sheets("CheckList").Range("A2:A" & ValidateL), rngCell.Offset(, -2)) <> 0 And _
      WorksheetFunction.CountIf(Sheets("CheckList").Range("C2:C" & ValidateL), rngCell.Offset(, -1)) = 0 And _
      WorksheetFunction.CountIf(Sheets("CheckList").Range("D2:D" & ValidateL), rngCell.Offset(, 2)) = 0 And _
      WorksheetFunction.CountIf(Sheets("CheckList").Range("E2:E" & ValidateL), rngCell.Offset(, 1)) = 0 Then
       MsgBox "Please validate this combo " & rngCell & " Row Num: " & rngCell.Row
       End
    End If
    
Next

Thanks!
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
yes this is the complete code. Forgot to add variable declare and
Code:
Dim rngCell As Range
add
Code:
End Sub
at the end. though
 
Last edited:
Upvote 0
Okay, I was just trying out the code,
You have no dim for or set variable for rngcell or rowlast
 
Upvote 0
Okay, I was just trying out the code,
You have no dim for or set variable for rngcell or rowlast

my bad rowlast is a private function.

Code:
Private Function rowLast()
    rowLast = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
End Function

Thanks for the support!
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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