Macro to check if current cell value is 1 and previous cell wa
Thank you.
It worked.
"Ryan H" wrote:
Put this code in the worksheet module. This code will only run if a cell
value is changed in C42:M42. It will only show an alert if the Target cell
value is 1 or 2 and the cell to the left of it is 0. Hope this helps! If
so, let me know, click "YES" below.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range
Set MyRange = Intersect(Target, Range("C42:M42"))
If Not MyRange Is Nothing Then
With Target
If (.Value = 1 Or .Value = 2) And .Offset(, -1).Value = 0 Then
MsgBox "ALERT"
End If
End With
End If
End Sub
--
Cheers,
Ryan
"wissam" wrote:
Hi.
I have a range of cells (C42:M42) where the user can enter values of 0,1,or
2 only (set up via data validation).
I need help with a code to do the following: if the worksheet user enters a
value or changes the value in a cell in the above range (C42:M42), then excel
would automatically check ( via a macro?) the value entered and compare this
value to the value present in the previous cell on the same row. If the value
entered is 1 or 2, and the value in the previous cell was 0, then it would
give a msgbox alert.
Any help is appreciated.
Thank you very much.
|