Change Event Macro on Condition

rex759

Well-known Member
Joined
Nov 8, 2004
Messages
610
Office Version
  1. 365
Platform
  1. Windows
Hello,
I wrote a change event macro based on the user entering a number higher than 1 in the range D4:D27. It’s working, currently.

I want to add a condition so the macro only runs if the corresponding cell in column B has the word “Survey” or “Review”.

I tried using an And statement on this line but could not get it to work.

Code:
If Not Intersect(Target, Range("D4:D27")) Is Nothing Then


Any help is greatly appreciated.

Below is a snippet of the code.


Code:
'if the user enters a number other than 1 in column D
If Not Intersect(Target, Range("D4:D27")) Is Nothing Then
    b = Target.Value
        If b > 1 Then

'find last range
 Dim LastR As Long
    With Worksheets("Totals")
      LastR = .Cells(.Rows.Count, "S").End(xlUp).Row
      LastR = LastR + 1
    End With
    
myname = Target.Offset(0, 2).Value
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try:

Code:
If Not Intersect(target, Range("D4:D27")) Is Nothing And (Cells(target.Row, "B").Value = "Survey" Or Cells(target.Row, "B").Value = "Review") Then
 
Upvote 0
Try:

Code:
If Not Intersect(target, Range("D4:D27")) Is Nothing And (Cells(target.Row, "B").Value = "Survey" Or Cells(target.Row, "B").Value = "Review") Then

Ugh, I wasnt even close. Works perfectly. Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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