+ Reply to Thread
Results 1 to 5 of 5

To run a macro when values of the cells modified?

Hybrid View

  1. #1
    Registered User
    Join Date
    08-20-2008
    Location
    Finland
    Posts
    13

    To run a macro when values of the cells modified?

    Hi,

    I would need to get a macro running every time when the document is modified.

    Private Sub Workbook_SheetChange(ByVal Sh As Object, _
            ByVal Source As Range)
    This code would work, but the problem is that the macro edits the cells, and therefore it ends up running over and over again...

    Thanks!

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    It would probably be more helpful if we saw your code
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    08-20-2008
    Location
    Finland
    Posts
    13
    This is a simplified example (the actual code runs also a macro which changes the y-axis scales of charts located on their own sheets...).

    When I edit the value of a cell, excel gets stuck prompting "hi!" over and over again...

    "ThisWorkbook":
    Private Sub Workbook_SheetChange(ByVal Sh As Object, _
            ByVal Source As Range)
    
    msgbox "hi!"
    
    muokkaus "hei"
    
    
    End Sub
    and

    "Module 1":
    Sub muokkaus(hei As Variant)
    
    
    With Sheets("scatter_25_8")
    Sheets("Adjustments").Range("B11").value = .Axes(xlValue).MaximumScale
    Sheets("Adjustments").Range("B11").value = .Axes(xlValue).MinimumScale
    
    End With
    
    End Sub

  4. #4
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Try this:

    Private Sub Workbook_SheetChange(ByVal Sh As Object, _
            ByVal Source As Range)
        Application.EnableEvents = False
    
    'your code
    
        Application.EnableEvents = True
    End Sub
    HTH

    Jason

  5. #5
    Registered User
    Join Date
    08-20-2008
    Location
    Finland
    Posts
    13
    Quote Originally Posted by jasoncw View Post
    Try this:

    Private Sub Workbook_SheetChange(ByVal Sh As Object, _
            ByVal Source As Range)
        Application.EnableEvents = False
    
    'your code
    
        Application.EnableEvents = True
    End Sub
    HTH

    Jason
    That seems to work, thanks!

    However, I realized that the macro should also automatically run when the y-axis scale of a chart is manually adjusted (format axis). Is there a way to carry this out?

    Edit: I would also need to distinguish the cases, where the user has manually changed the y-axis scale, and where edited the values of a cell...

    Thanks for your time.
    Last edited by tms_; 10-28-2008 at 12:03 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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