running two change by value in one worksheet

armchairandy

Board Regular
Joined
Mar 27, 2012
Messages
53
Not sure if this is possible.. but

I already have a change event in a work sheet - works as I want it to

Private Sub Worksheet_Change(ByVal Target As Range)

Dim KeyCells As Range
Set KeyCells = Range("G17:G205")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
Dim iCol As Integer
Range("Y3").Activate
For iCol = 0 To 100
If ActiveCell.Offset(0, iCol).Value = Range("B1").Value Then
ActiveCell.Offset(1, iCol).Value = Range("H14").Value
Exit For
End If
If iCol = 100 Then
'MsgBox "This Metric is not due to Start yet!"
End If
Next iCol
End If
End Sub

Kindly donated by WaterGypsy

I have a drop-box with two options in another cell on the same worksheet, where one option would runs macro, the other option does nothing.

How can I enter both in the Change by value section? I do not want both codes running if only one range changes. Alternatively is there a mechanism where I can run the drop-box option separately.

Any help appreciated

Andrew
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Is the drop-box a data validation dropdown?
If so what cell is it in & what needs to happen?
 
Upvote 0
If you have a second Worksheet_Change macro based on your drop down list, please post it as well. If you don't yet have it, then explain in detail what you want the second Worksheet_Change macro to do.
 
Upvote 0
Mumps

This is the second "macro" based on the value in cell D7

Sheets("M1").Activate
If (Range("D7")) = "Automatic" Then
Exit Sub
Else
Dim Answer As String
Dim MyNote As String
MyNote = "Are you sure you want to continue? This will delete the formulas in the actual column"
Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "CWC Data Deletion")

If Answer = vbYes Then

Sheets("M1").Activate

Range("H17:H205").Select
Selection.Locked = False
Selection.FormulaHidden = False
Selection.ClearContents

End If
End If
End Sub

Andrew
 
Upvote 0
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

   Dim KeyCells As Range
   Set KeyCells = Range("G17:G205")
   If Not Application.Intersect(KeyCells, Range(Target.Address)) _
         Is Nothing Then
      Dim iCol As Integer
      Range("Y3").Activate
      For iCol = 0 To 100
         If ActiveCell.Offset(0, iCol).Value = Range("B1").Value Then
            ActiveCell.Offset(1, iCol).Value = Range("H14").Value
            Exit For
         End If
         If iCol = 100 Then
            'MsgBox "This Metric is not due to Start yet!"
         End If
      Next iCol
   ElseIf Target.Address(0, 0) = "D7" Then
      If Target = "Automatic" Then Exit Sub
      Dim Answer As String
      Dim MyNote As String
      MyNote = "Are you sure you want to continue? This will delete the formulas in the actual column"
      Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "CWC Data Deletion")
      
      If Answer = vbYes Then
         With Sheets("M1").Range("H17:H205")
            .Locked = False
            .FormulaHidden = False
            .ClearContents
         End With
      End If
   End If
End Sub
 
Last edited:
Upvote 0
I assume that the second macro is a Worksheet_Change event. Is it triggered by a change in D7? Is the macro in the worksheet code module for "M1"?
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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