PDA

View Full Version : Solved: Worksheet_Change with 2 requirements



JimS
04-05-2011, 12:17 PM
I'm using a Worksheet_Change function to run a Macro when cell C12 is changed.

How can this be modified so that it looks at cell C20 also.

BOTH cell must contain data (neither one can be blank). Also if one is blank can the Worksheet_Change function make the blank cell the Active cell?

So if c12 has data but c20 is blank - c20 will become the active cell or if c20 has data but c12 is blank then c12 will become the active cell.

Once both cells have data then the Macro can run.

Below is what I'm currently using (just to monitor for C12).

Any ideas?

Thanks...

JimS


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Intersect(Target, Me.Range("C12")) Is Nothing Then Exit Sub

On Error GoTo endit
Application.EnableEvents = False

' On Module-3
Run ("Select")

endit:
Application.EnableEvents = True
End Sub

mikerickson
04-05-2011, 12:52 PM
Try
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error Goto endit
If Not Intersect(Target, Me.Range("C12,20")) Is Nothing Then
Application.EnableEvents = False

If CStr(Range("C12").Value) = vbNullString Then
Range("C12").Select
Beep
ElseIf CStr(Range("C20").Value) = vbNullString Then
Range("C20").Select
Beep
Else
Call theMacro
End If

End If
endit:
Application.EnableEvents = True
End Sub

stanleydgrom
04-05-2011, 01:01 PM
mikerickson,

You missed one C





If Not Intersect(Target, Me.Range("C12,C20")) Is Nothing Then

JimS
04-05-2011, 01:33 PM
Mikerickson, Thanks - just what I needed.

stanleydgrom, Thanks, I caught that.

Thanks again...

JimS

mikerickson
04-05-2011, 03:55 PM
Stanley, thanks for catching that

Glad it worked