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?
 
Changing values in C3 and D3.
This is Macro 1

Code:
Sub Macro1(bbb, NewValue As String)




    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    




    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)




    strbody = "Hi there" & vbNewLine & vbNewLine & _
              "Cell " & bbb & " is changed to " & NewValue & vbNewLine & _
              "This is line 2" & vbNewLine & _
              "This is line 3" & vbNewLine & _
              "This is line 4"




    On Error Resume Next
    With OutMail
        .To = "abc@gmail.com"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = strbody
       .Attachments.Add ("C:\Users\\Desktop\abc.xlsm")
        
        .Display
    End With
    On Error GoTo 0




    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

It sends an email.
 
Last edited:
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
IronHat, are you saying you only want to run Macro1 after cells C3 and D3 have both been changed? In this case, you must understand the dilemma which is that the only way the Worksheet_Change event is going to pick up on both cells being changed is if they are both changed at the same time (such as highlighting both cells, typing a value and then pressing CTRL+ENTER). You do understand this, yes?
 
Last edited:
Upvote 0
Maybe ...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Static bC3        As Boolean
  Static bD3        As Boolean

  Select Case Target.Address
    Case "$C$3"
      bC3 = True
      If bD3 Then Call Macro1("C3", Target.Value)
      bD3 = False
    Case "$D$3"
      bD3 = True
      If bC3 Then Call Macro1("D3", Target.Value)
      bC3 = False
    Case Else
      bC3 = False
      bD3 = False
  End Select
End Sub
 
Upvote 0
"It's not working" doesn't advance your cause. Does the code trigger? Have you set a breakpoint and stepped through it?

It should run the macro if you modify C3 and then D3, or D3 and then C3.
 
Upvote 0

Forum statistics

Threads
1,215,777
Messages
6,126,838
Members
449,343
Latest member
DEWS2031

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