Can A Cell Change Run A Macro??

rockyw

Well-known Member
Joined
Dec 26, 2010
Messages
1,196
Office Version
  1. 2010
Platform
  1. Windows
I have a workbook where I paste a report on sheet 1, formulas on sheet 3 look for data and return it to E3:E24. This maro copies and pastes it on sheet 2 E3:E24, can I fire this macro WITHOUT me clicking anything? Can a simple cell change, any cell change in the range of sheet 3 E3:E24 make this maro run? Thnaks for any help.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("E3")) Is Nothing Then Macro
    Sheets("Sheet3").Select
    Range("E3:E24").Select
    Selection.Copy
    Sheets("Sheet2").Select
    Range("E3:E24").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
If you put this in sheet3's code module, it should do what you want
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim keyRange As Range
    Set keyRange = Me.Range("E3:E24")

    If Not Application.Intersect(Target, keyRange) Is Nothing Then
        Sheet2.Range(keyRange.Address).Value = keyRange.Value
    End If
End Sub
 
Upvote 0
Thank you for the help, I put that in sheet 3 Module 1? And will this still paste special? Thanks
 
Upvote 0
I tried it in Module 1 and 3, nothing happens on sheet 2. The macro will not work unless I run it.
 
Upvote 0
In the Project Explorer, double click on Sheet3's icon. A window should appear, named something like
Workbook1.xlsm - Sheet3 (code)

That's the window to paste that event code into.
 
Upvote 0
Will it make a differance if I named the workbook? Nothing happens now, The workbook is called ProductionShellInventory
 
Upvote 0
That would change the name of the window.
The way to insure that the code is pasted in the correct module is to use the VBEditor's Project Explorer and double click on Sheet3's icon. That icon should be in a folder named Microsoft Excel Objects.
 
Upvote 0
Yes I have it in ProductionShellInventory - Sheet 3 (code) But it will not run on it's own. I can make it run but it will not run when sheet 3 updates the data. Thanks for the help
 
Upvote 0
Try Precedents. e.g.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim keyRange As Range
    Set keyRange = Me.Range("E3:E24")

    If Not Application.Intersect(Target, keyRange.Precedents) Is Nothing Then
        Sheet2.Range(keyRange.Address).Value = keyRange.Value
    End If
End Sub

The other way to be sure that sheet code is put on the right sheet, right click the sheet's tab, View Code, and then paste.
 
Upvote 0
I beleive I have the code in the correct area. The other code did not work, it messed up the codisional formating. This code works and the formating works also. Now to make sure you understand, I am only using paist on sheet one. That's it, if I put soemthing in sheet 3 manualy, then the macro runs. Will something run the macro when the cells fill with a formula only? This all works when I use a command button to run the macro. I would just like this code as written to run when the cells fill on sheet 3. Thanks for your interest.
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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