+ Reply to Thread
Results 1 to 6 of 6

"Worksheet_Change" fails if change is initiated from another sheet

  1. #1
    Registered User
    Join Date
    03-23-2015
    Location
    us
    MS-Off Ver
    365
    Posts
    93

    "Worksheet_Change" fails if change is initiated from another sheet

    I have a script to add date to "A" when "D" changes.
    --------------------------
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Cells.Count = 1 And Target.Column = 4 Then
    Target.Offset(0, -3) = Date
    End If
    End Sub
    -----------------
    Works fine, until I had "D" populated, thru this formula, from another sheet "Worksheet".
    =IF(Worksheet!D26=0,"nutin",Worksheet!D26)
    -----------------------
    Now when "D" changes [is populated] from this formula, or sheet "Worksheet", the date does not show in "A".
    In other words, when "D" changes via this formula, the script does not work and "A" does not populate with the date.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: "Worksheet_Change" fails if change is initiated from another sheet

    The Worksheet_Change event only fires when a cell is changed manually, not when a formula recalculates and the cell shows another value. You may want to place a Worksheet_Change event on the cell where the data is physically entered by the user.

  3. #3
    Registered User
    Join Date
    03-23-2015
    Location
    us
    MS-Off Ver
    365
    Posts
    93

    Re: "Worksheet_Change" fails if change is initiated from another sheet

    Not feasible. Is there another way around this?

  4. #4
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: "Worksheet_Change" fails if change is initiated from another sheet

    Hi Skipro,

    Nice to see you in this forum as well.

    Place the following UDF in a standard module:
    Please Login or Register  to view this content.
    Now for all your formulas in column D, place them inside the UDF formula for the call:
    ex. Sheet1 cell D1 has the formula =Sheet2!A1*2

    Change the formula in D1 =Calling(Sheet2!A1*2)

    In the worksheet module, place your following code
    Please Login or Register  to view this content.
    The UDF returns the formula result to the cell as if the formula would without UDF, however, it is able to capture the cell that was just changed (CalcCell). Since the calculated cell triggers the WorkSheet_Calculate event, we can use the CaclCell's address to populate column A.

    HTH,
    Maud

    skipro1.png

  5. #5
    Registered User
    Join Date
    03-23-2015
    Location
    us
    MS-Off Ver
    365
    Posts
    93

    Re: "Worksheet_Change" fails if change is initiated from another sheet

    Maud,
    Thanks.
    To be clear:
    Sheet1 is where I enter data in D
    Sheet2 is where I want D[Sheet2] to be populated from D[Sheet1] and have the date populated in A[sheet2]. I want the date entered to be non volatile, remain[not change] after a refresh.
    If there is no entry in D [Sheet1] there should be no entry or changes in A or D in Sheet2.
    When I enter an amt in D[Sheet1], then I want that amount to populate D [Sheet2] and have the date populate in A[Sheet2], and be non volatile.
    ++++++++++++++++++++
    At your suggestion:
    I added standard module
    I added worksheet module for Sheet2.

    I think you want me to add the formula "=Calling(Sheet2!A1*2)" to D[sheet2]

    This does not work as described above for me.

  6. #6
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: "Worksheet_Change" fails if change is initiated from another sheet

    Hi Skipro,

    Perhaps I should have better explained.

    Assuming that sheet1 currently has the formulas in column D and the date desired to populate Column A, in column D of that sheet you will place the UDF.

    Now the formula, Sheet2!A1*2 was only a sample. You would use your formula as the parameter for the UDF:

    =Calling(IF(Worksheet!D26=0,"nutin",Worksheet!D26))

    The worksheet_Calculate event procedure goes in the worksheet module of the sheet1 where the code works on the offset of the cell whose formula has been calculated (CalcCell). The public range object CalcCell was set in the UDF.

    So, If you change a value in the formula, the UDF will grab the formula as a parameter then returns the the value of the formula back to the cell as the formula would by itself however, the UDF can do something that the formula alone can't and that is to identify which cell is being calculated (CalcCell). Once CalcCell is known, the Worksheet_Calculate event knows where to place the date.

    Below is a split screen shot of sheet1 and the sheet called Worksheet. When the cell value referenced in the formula changes on Worksheet D1, the UDF returns the value of the formula and sets the CellCalc range object.

    I hope that gives a clearer picture.
    Maud

    Skipro2.png
    Last edited by Maudibe; 09-22-2017 at 08:01 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Change worksheets in ...Worksheet_Change!
    By Dturazza in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-15-2014, 09:24 AM
  2. change the (Worksheet_Change) event for a module (Sub).
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-07-2012, 01:37 PM
  3. change event macro to evaluate windows user who initiated the change then send email
    By pmanoloff in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-23-2012, 03:31 PM
  4. ODBC Connection Fails on Name Change
    By Harle000 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-21-2011, 07:10 PM
  5. Change Worksheet_Change sub to an ordinary sub
    By Glio in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-18-2008, 11:39 AM
  6. Replies: 2
    Last Post: 06-19-2006, 12:10 PM
  7. [SOLVED] Change event fails to work
    By Mark F in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-10-2005, 08:10 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1