Running Macro when change made to worksheet

jtay

New Member
Joined
Feb 16, 2012
Messages
2
The intent of the code below is to run the marco HideCol when a change is made in cell C10. If I actually change the value in C10 it works. However, I have C10 linked to another worksheet (=anotherpage!A13). When the value changes, my macro is not executing.

Here is the code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim changed As Range
Set changed = Range("C10")
If Not Intersect(Target, changed) Is Nothing Then
HideCol
End If
End Sub

Any thoughts on how to make this work? Thanks in advance.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi jtay and Welcome to the Board
Try
changing
Code:
Sub Worksheet_Change(ByVal Target As Range)

TO

Code:
Private Sub Worksheet_Calculate()
 
Upvote 0
Thanks Michael M!

When I do that, it no longer likes the line:

If Not Intersect(Target, changed) Is Nothing Then

Sorry, I'm new to VBA. I tried taking target out of the line above, but that didn't seem to help?
 
Upvote 0
Ok, my bad, I didn't read the question correctly
You'll need to put a reference cell in the sheet, see my example.
Basically this triggers the change, "Z1" can be anywhere, and will = C10, when the formula changes C10 the event is trigered and the new value transferred to "Z1"
Code:
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
    If Range("C10") <> Range("Z1") Then
        Range("Z1") = Range("C10")
        HideCol
    End If
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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