WorkSheet Change Events

skd25

New Member
Joined
Mar 27, 2012
Messages
37
I am using the macro below to trigger the code when some values in cells on Sheet 1 changes. However, I would like to have another change of events in Sheet 2 that will drive the output (results) on Sheet 1. Would like results on Sheet 1 to reflect a change in cells on Sheet 2. The range I have specified only reflects Sheet 1. Is there anyway I can make this happen?

Code on Sheet 1:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim KeyCells As Range

    Set KeyCells = Range("A1:B10")
    
If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
    
    Application.EnableEvents = False
    Range("B2:B10").FormulaR1C1 = "=VLOOKUP(RC[-1],array,2,FALSE)"
    Range("B3:B10").value = Range("B3:B10").value
    Application.EnableEvents = True
    
End If
    
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Is there anyway I can make this happen?

You just have to qualify the object.

Code:
    Sheet2.Range("B2:B10").FormulaR1C1 = "=VLOOKUP(RC[-1],array,2,FALSE)"
'or
    Worksheets(2).Range("B3:B10").value = Range("B3:B10").value
'or
    Worksheets("MySheetName").Range("B3:B10").value = Range("B3:B10").value
 
Upvote 0
Try this in the Sheet2 code module.

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Worksheet_Change([color=darkblue]ByVal[/color] Target [color=darkblue]As[/color] Range)

    [color=darkblue]If[/color] [color=darkblue]Not[/color] Application.Intersect(Range("array"), Target) [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]

        [color=darkblue]With[/color] Sheets("Sheet1").Range("B2:B10")
            Application.EnableEvents = [color=darkblue]False[/color]
            .FormulaR1C1 = "=VLOOKUP(RC[-1],array,2,FALSE)"
            .Value = .Value
            Application.EnableEvents = [color=darkblue]True[/color]
        [color=darkblue]End[/color] [color=darkblue]With[/color]

    [color=darkblue]End[/color] [color=darkblue]If[/color]

End [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,202,984
Messages
6,052,914
Members
444,612
Latest member
FajnaAli

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