I am trying to build a message box flag if the row count is over 3 which works AND if the person's age is over 40 in colEcell. It recognizes the value in colEcell but it pops up the flag no matter what. I just want it to pop up if the used row count is over 3 and if anyone in colEcell is over 40.
Any ideas where my code is flawed?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim colAcell As Range, colBcell As Range, colCcell As Range, colDcell As Range, lastRow As Range
Dim wks As Worksheet
Set wks = Worksheets("DataEntry")
Set colAcell = wks.Range("AG1")
Set lastRow = colAcell.SpecialCells(xlCellTypeLastCell)
Do Until colAcell.Row > lastRow.Row
Set colBcell = colAcell.Offset(0, 1)
Set colEcell = colAcell.Offset(2, 32)
If WorksheetFunction.CountA(Range("A1", Range("A" & Rows.Count).End(xlUp))) > 3 And (colEcell.Value > 39) Then
Cancel = True
MsgBox "Please ensure to give letter to employee."
'MsgBox colEcell.Value
End
End If
Set colAcell = colAcell.Offset(1)
Loop
Any ideas where my code is flawed?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim colAcell As Range, colBcell As Range, colCcell As Range, colDcell As Range, lastRow As Range
Dim wks As Worksheet
Set wks = Worksheets("DataEntry")
Set colAcell = wks.Range("AG1")
Set lastRow = colAcell.SpecialCells(xlCellTypeLastCell)
Do Until colAcell.Row > lastRow.Row
Set colBcell = colAcell.Offset(0, 1)
Set colEcell = colAcell.Offset(2, 32)
If WorksheetFunction.CountA(Range("A1", Range("A" & Rows.Count).End(xlUp))) > 3 And (colEcell.Value > 39) Then
Cancel = True
MsgBox "Please ensure to give letter to employee."
'MsgBox colEcell.Value
End
End If
Set colAcell = colAcell.Offset(1)
Loop