+ Reply to Thread
Results 1 to 4 of 4

Worksheet_Change() not working with formulae

Hybrid View

  1. #1
    Registered User
    Join Date
    04-29-2015
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    82

    Worksheet_Change() not working with formulae

    Good Afternoon,

    At the moment I'm using this code to update a table with month and years and put the value of cell BY3 into column D when it changes. However I've since learned that Worksheet_Change does not work with formulae calculations and I should be using Worksheet_Calculate(). How would I get the same results from the current below - but when BY3 is changed by a formula it also triggers the VBA? At the moment changing to worksheet_calculate() doesn't weild any results and only errors.

    Your help would be appreciated.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("BY3")) Is Nothing Then
      Cells(Month(Date) + 1, "D") = WorksheetFunction.Max( _
        Val(Cells(Month(Date) + 1, "D")), Range("BY3").Value)
    End If
    End Sub

  2. #2
    Registered User
    Join Date
    04-29-2015
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Worksheet_Change() not working with formulae

    Think I may have solved my issue.

    Private Sub Worksheet_Calculate()
    Static oldval
    If Range("BY3").Value <> oldval Then
        oldval = Range("BY3").Value
          Cells(Month(Date) + 1, "D") = WorksheetFunction.Max( _
        Val(Cells(Month(Date) + 1, "D")), Range("BY3").Value)
    End If
    End Sub
    Anyone with more experience confirm that this will solve my issue and will continue to do what i want? (I can't change the month on my computer because of Admin rights)

  3. #3
    Registered User
    Join Date
    04-29-2015
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Worksheet_Change() not working with formulae

    Think I may have solved my issue.

    Private Sub Worksheet_Calculate()
    Static oldval
    If Range("BY3").Value <> oldval Then
        oldval = Range("BY3").Value
          Cells(Month(Date) + 1, "D") = WorksheetFunction.Max( _
        Val(Cells(Month(Date) + 1, "D")), Range("BY3").Value)
    End If
    End Sub
    Anyone with more experience confirm that this will solve my issue and will continue to do what i want? (I can't change the month on my computer because of Admin rights)

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Worksheet_Change() not working with formulae

    Yes it is the way I found but I should disable event to avoid confusion
        
    Application.EnableEvents = False
           oldval = Range("BY3").Value
          Cells(Month(Date) + 1, "D") = WorksheetFunction.Max( _
        Val(Cells(Month(Date) + 1, "D")), Range("BY3").Value)
        Application.EnableEvents = True
    - Battle without fear gives no glory - Just try

+ 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] Private sub worksheet_change not working
    By DavidBW in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-21-2013, 06:06 PM
  2. worksheet_change not working is ther another way to do it
    By ELFM in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-10-2013, 01:49 AM
  3. worksheet_change not working
    By JChandler22 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-07-2010, 06:56 PM
  4. Worksheet_Change not working
    By BML1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2009, 07:50 PM
  5. Worksheet_Change not working
    By shamidi in forum Excel General
    Replies: 2
    Last Post: 01-09-2007, 11:29 AM

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