Worksheet Change for multiple cells

macsask

New Member
Joined
Dec 8, 2018
Messages
2
I have been trying to figure out how to get worksheet to run macro when only certain cells change.
Do I have to create a worksheet change for each cell or can it be written in to one worksheet change

For example, I want macro to run if HA5 = 1, as well as every other +1000 row of column (HA1005, HA2005, ect)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim MainCells As Range

    Set MainCells = Range("HA5")

    If Not Application.Intersect(MainCells, Range(Target.Address)) _
           Is Nothing Then
 
        Select Case Target.Value
        Case "1"
        Call Macro2
        End Select
        End If

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi & welcome to MrExcel.
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

   If Not Intersect(Target, Range("HA5,HA1005,HA2005,HA3005")) Is Nothing Then
      If Target.Value = "1" Then Call Macro2
   End If
End Sub
 
Upvote 0
Fluff thank you for response
After some thought I have decided it would make more sense if my Macro was modified and I left the Worksheet change to include all the cells in my HA column Range.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

   If Not Intersect(Target, Range("HA5:HA76593")) Is Nothing Then
      If Target.Value = "1" Then Call Macro2
   End If
End Sub

But that gives me another snag in Macro when modifying it to recognize active row and autofill range.
Code:
         Range("FW" & ActiveCell.Row - 1).Resize(, 30).Select
        'auto fill range 1000 rows, range(FW:GZ)
        'go back to original activecell on completion
        Selection.AutoFill Destination:=Range("FW & ActiveCell.Row - 1:GZ" & 1000), Type:=xlFillDefault
 
Upvote 0
Either put the macro into the change event, rather than having it separate, or do something like
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

   If Not Intersect(Target, Range("HA5:HA76593")) Is Nothing Then
      If Target.Value = "1" Then Call Macro2(Target.Row)
   End If
End Sub

Sub Macro2(Rw As Long)
Range ("FW" & Rw)
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,731
Members
449,093
Latest member
Mnur

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