+ Reply to Thread
Results 1 to 4 of 4

Worksheet_Calculate question

  1. #1
    Barb Reinhardt
    Guest

    Worksheet_Calculate question

    I have the following macro:

    Private Sub Worksheet_Calculate()
    If ThisWorkbook.Name = ActiveWorkbook.Name Then
    Application.ScreenUpdating = False
    If ChartObjects.Count > 0 Then
    With ChartObjects(ChartObjects.Count)
    AxisScale .Chart
    End With
    End If
    Application.ScreenUpdating = True
    End If
    End Sub

    I want it to only run when for the worksheet that it's "attached" to. It
    seems to be running whenever I change anything on another worksheet in the
    workbook. What do I need to change?

    Thanks in advance,
    Barb Reinhardt

  2. #2
    Barb Reinhardt
    Guest

    RE: Worksheet_Calculate question

    In addition, thre is a possibility that I'll have multiple worksheets with an
    embedded chart on the worksheet and I'll want to set up a Worksheet_calculate
    event for each worksheet. Can this be done and what else might I need to
    change in this.

    "Barb Reinhardt" wrote:

    > I have the following macro:
    >
    > Private Sub Worksheet_Calculate()
    > If ThisWorkbook.Name = ActiveWorkbook.Name Then
    > Application.ScreenUpdating = False
    > If ChartObjects.Count > 0 Then
    > With ChartObjects(ChartObjects.Count)
    > AxisScale .Chart
    > End With
    > End If
    > Application.ScreenUpdating = True
    > End If
    > End Sub
    >
    > I want it to only run when for the worksheet that it's "attached" to. It
    > seems to be running whenever I change anything on another worksheet in the
    > workbook. What do I need to change?
    >
    > Thanks in advance,
    > Barb Reinhardt


  3. #3
    Dave Peterson
    Guest

    Re: Worksheet_Calculate question

    You could create a worksheet_calculate for each worksheet and check to see what
    worksheet is active:

    Private Sub Worksheet_Calculate()
    If Me.Parent.Name = ActiveWorkbook.Name Then
    If Me.Name = ActiveSheet.Name Then

    But maybe it would be better to use the Workbook_sheetCalculate event

    Option Explicit
    Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
    If Me.Name = ActiveWorkbook.Name Then
    If Sh.Name = ActiveSheet.Name Then
    'do your stuff...





    Barb Reinhardt wrote:
    >
    > In addition, thre is a possibility that I'll have multiple worksheets with an
    > embedded chart on the worksheet and I'll want to set up a Worksheet_calculate
    > event for each worksheet. Can this be done and what else might I need to
    > change in this.
    >
    > "Barb Reinhardt" wrote:
    >
    > > I have the following macro:
    > >
    > > Private Sub Worksheet_Calculate()
    > > If ThisWorkbook.Name = ActiveWorkbook.Name Then
    > > Application.ScreenUpdating = False
    > > If ChartObjects.Count > 0 Then
    > > With ChartObjects(ChartObjects.Count)
    > > AxisScale .Chart
    > > End With
    > > End If
    > > Application.ScreenUpdating = True
    > > End If
    > > End Sub
    > >
    > > I want it to only run when for the worksheet that it's "attached" to. It
    > > seems to be running whenever I change anything on another worksheet in the
    > > workbook. What do I need to change?
    > >
    > > Thanks in advance,
    > > Barb Reinhardt


    --

    Dave Peterson

  4. #4
    Barb Reinhardt
    Guest

    Re: Worksheet_Calculate question

    Thanks so much.

    "Dave Peterson" wrote:

    > You could create a worksheet_calculate for each worksheet and check to see what
    > worksheet is active:
    >
    > Private Sub Worksheet_Calculate()
    > If Me.Parent.Name = ActiveWorkbook.Name Then
    > If Me.Name = ActiveSheet.Name Then
    >
    > But maybe it would be better to use the Workbook_sheetCalculate event
    >
    > Option Explicit
    > Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
    > If Me.Name = ActiveWorkbook.Name Then
    > If Sh.Name = ActiveSheet.Name Then
    > 'do your stuff...
    >
    >
    >
    >
    >
    > Barb Reinhardt wrote:
    > >
    > > In addition, thre is a possibility that I'll have multiple worksheets with an
    > > embedded chart on the worksheet and I'll want to set up a Worksheet_calculate
    > > event for each worksheet. Can this be done and what else might I need to
    > > change in this.
    > >
    > > "Barb Reinhardt" wrote:
    > >
    > > > I have the following macro:
    > > >
    > > > Private Sub Worksheet_Calculate()
    > > > If ThisWorkbook.Name = ActiveWorkbook.Name Then
    > > > Application.ScreenUpdating = False
    > > > If ChartObjects.Count > 0 Then
    > > > With ChartObjects(ChartObjects.Count)
    > > > AxisScale .Chart
    > > > End With
    > > > End If
    > > > Application.ScreenUpdating = True
    > > > End If
    > > > End Sub
    > > >
    > > > I want it to only run when for the worksheet that it's "attached" to. It
    > > > seems to be running whenever I change anything on another worksheet in the
    > > > workbook. What do I need to change?
    > > >
    > > > Thanks in advance,
    > > > Barb Reinhardt

    >
    > --
    >
    > Dave Peterson
    >


+ 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