Problem with Target.Range

IronHat

New Member
Joined
May 6, 2015
Messages
12
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If (Target.Range="$C$3") And (Target.Range=$C$3) Then
    Call Macro1(Target.Address(False, False), Target.Value)
End If
End Sub

I am trying it to detect changes made in cell C3 and D3 and if changes are made in both the cells only then call macro 1.
However And is not working. If (Target.Range=$C$3) And (Target.Range=$D$3) doesnt work. I know it works with OR.
What to do?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try
Code:
If Target.Address = "$C$3" Then


Its still not calling macro 1 on change in both the cells.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If (Target.Address = "$C$3") And (Target.Address = "$D$3") Then
    Call Macro1(Target.Address(False, False), Target.Value)
End If
End Sub
 
Last edited:
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rInt          As Range

  rInt = Intersect(Target, Range("C3:D3"))
  If Not rInt Is Nothing Then
    If rInt.Cells.Count = 2 Then
      Call Macro1(Target.Address(False, False), Target.Value)
    End If
  End If
End Sub

I'm skeptical about the arguments passed to Macro1, though. They would have to be a String and a Variant.
 
Upvote 0
If you change the value in cell C3 the event fires and target.address is "$C$3", there is nothing there that waits for you to change cell D3. Change a cell the event fires.
If you highlight cell C3 and D3 and enter a value and hit control + enter then both cells will get the same value and the target.address will be "$C$3:$D$3", but highlight them both and entering a value and just normally hitting enter will only result in C3 being the target.
You have to come up with another tactic if you want to check if C3 has been changed from a former value when you change D3 or vice versa.
If this is even what you are after, which to me it sounds like that is what you are after, or maybe I'm reading your original post wrong.
Public variables perhaps that checks the values in the cells when the worksheet opens?
 
Last edited:
Upvote 0
Thanks for the reply shg
I am getting an error message at
rInt = Intersect(Target, Range("C3:D3"))
 
Last edited:
Upvote 0
Sorry,

Code:
[COLOR="#FF0000"]Set [/COLOR]rInt = Intersect(Target, Range("C3:D3"))
 
Upvote 0
What are you doing from the user interface to trigger it?
 
Upvote 0

Forum statistics

Threads
1,214,605
Messages
6,120,476
Members
448,967
Latest member
visheshkotha

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