+ Reply to Thread
Results 1 to 4 of 4

Multiple private sub

  1. #1
    Registered User
    Join Date
    03-30-2015
    Location
    Groningen, Netherlands
    MS-Off Ver
    2007
    Posts
    6

    Multiple private sub

    Hi,

    I have two different VBA functions: goalseek and automatic change of x- and y-axis ranges.
    I would like to have both calculated in the same sheet. The codes are working indepentenly (on different sheets), but how can I get this working on 1 single sheet.

    Thanks in advance!

    The code:

    Private oldGoalSeek1 As Variant
    Private oldGoalSeek2 As Variant


    Private Sub CommandButton1_Click()
    ActiveWindow.SelectedSheets.PrintPreview ' preview
    End Sub


    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("GoalSeek1").Value <> oldGoalSeek1 Then
    Range("GoalSeek1").GoalSeek goal:=0, changingcell:=Range("ByChangingCell")
    oldGoalSeek1 = Range("GoalSeek1").Value
    End If
    If Range("GoalSeek2").Value <> oldGoalSeek2 Then
    Range("GoalSeek2").GoalSeek goal:=0, changingcell:=Range("ByChangingCell2")
    oldGoalSeek2 = Range("GoalSeek2").Value
    End If
    End Sub

    Private Sub Worksheet_Calculate()
    Dim cht As Chart
    Dim wks As Worksheet

    Set wks = ActiveSheet
    Set cht = wks.ChartObjects("Chart 3").Chart

    If wks.Range("$G$9").Value <> cht.Axes(xlCategory).MaximumScale Then
    cht.Axes(xlCategory).MaximumScale = wks.Range("$G$9").Value
    End If
    If wks.Range("$G$10").Value <> cht.Axes(xlCategory).MinimumScale Then
    cht.Axes(xlCategory).MinimumScale = wks.Range("$G$10").Value
    End If
    If wks.Range("$G$11").Value <> cht.Axes(xlCategory).MajorUnit Then
    cht.Axes(xlCategory).MajorUnit = wks.Range("$G$11").Value
    End If
    If wks.Range("$G$13").Value <> cht.Axes(xlValue).MaximumScale Then
    cht.Axes(xlValue).MaximumScale = wks.Range("$G$13").Value
    End If
    If wks.Range("$G$14").Value <> cht.Axes(xlValue).MinimumScale Then
    cht.Axes(xlValue).MinimumScale = wks.Range("$G$14").Value
    End If
    If wks.Range("$G$15").Value <> cht.Axes(xlValue).MajorUnit Then
    cht.Axes(xlValue).MajorUnit = wks.Range("$G$15").Value
    End If
    End Sub

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Multiple private sub

    First one is manual and second one is automatic. So confused what you are trying to do


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    03-30-2015
    Location
    Groningen, Netherlands
    MS-Off Ver
    2007
    Posts
    6

    Re: Multiple private sub

    Actually, after posting the thread, I found out the problem, and both calculations are executed automatically (when a value that is related to the calculation is changed only).
    If you're interested, I will still explain what I was trying to do (which works now ):

    - for 2 different cells, I want to do a GoalSeek automatically (at least, it is doing it automatically now when 1 of the values is changed)
    - then, for a graph (totally indepeding from the GoalSeek), I would like to have the axis automatically changed (the range), when a value of 1 of the axis (based on another cells' value) is changed.

    I'm wondering why the first one is manual and the second one is automatic? It looks like the first one is automatically calculated as well....

    Thanks!

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Multiple private sub

    Quote Originally Posted by thcook87 View Post
    I'm wondering why the first one is manual and the second one is automatic? It looks like the first one is automatically calculated as well....
    Oopss... The first one is targeted on the below code.

    Please Login or Register  to view this content.
    Also I have not read two other codes properly and treated rest of the two automatic codes as one.

    Anyhow glad you fixed it

+ 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] Multiple Private Sub Worksheet_Change Merge
    By darrenkaye in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-24-2013, 07:04 PM
  2. Multiple Private subs
    By LouiseH24 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-14-2011, 01:18 PM
  3. Checking Ranges on multiple sheets in the Private Module...
    By yunesm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-29-2010, 02:00 PM
  4. re : Possible to run private sub macros by writing another private
    By ddiicc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-26-2005, 12:05 AM
  5. [SOLVED] Private Sub Running Other Private Sub Inadvertently
    By Ross Culver in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-10-2005, 09:06 PM

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