+ Reply to Thread
Results 1 to 3 of 3

macro calling another macro + variables

  1. #1
    yo
    Guest

    macro calling another macro + variables

    I am trying to call another macro plot within a main macro that chooses data.
    I define a range "plotvalues" in the main macro and the second macro plots
    "plotvalues." However, the variable is not being recognized. here is the
    gist of what my code is like.

    Sub datasplit()
    ....
    plotvalues = ActiveSheet.Range("A1:L15").Address

    Macroplot
    End Sub()

    Sub Macroplot()
    Charts.Add
    ActiveChart.ChartType = xlXYScatter
    ActiveChart.SetSourceData Source:=Sheets("Input").Range(plotvalues),
    PlotBy:= _ xlColumns

    End Sub()

    Please help!


  2. #2
    Bernie Deitrick
    Guest

    Re: macro calling another macro + variables

    Dim plotvalues As Range

    Sub datasplit()
    Set plotvalues = ActiveSheet.Range("A1:L15")
    Macroplot
    End Sub

    Sub Macroplot()
    Charts.Add
    ActiveChart.ChartType = xlXYScatter
    ActiveChart.SetSourceData Source:=plotvalues, _
    PlotBy:=xlColumns

    End Sub


    OR

    Dim plotvalues As String

    Sub datasplit()
    plotvalues = ActiveSheet.Range("A1:L15").Address
    Macroplot
    End Sub

    Sub Macroplot()
    Charts.Add
    ActiveChart.ChartType = xlXYScatter
    ActiveChart.SetSourceData Source:=Sheets("Input").Range(plotvalues), _
    PlotBy:=xlColumns

    End Sub



    HTH,
    Bernie
    MS Excel MVP


    "yo" <yo@discussions.microsoft.com> wrote in message
    news:627F2608-B216-4D63-9B64-B137F280302C@microsoft.com...
    >I am trying to call another macro plot within a main macro that chooses data.
    > I define a range "plotvalues" in the main macro and the second macro plots
    > "plotvalues." However, the variable is not being recognized. here is the
    > gist of what my code is like.
    >
    > Sub datasplit()
    > ....
    > plotvalues = ActiveSheet.Range("A1:L15").Address
    >
    > Macroplot
    > End Sub()
    >
    > Sub Macroplot()
    > Charts.Add
    > ActiveChart.ChartType = xlXYScatter
    > ActiveChart.SetSourceData Source:=Sheets("Input").Range(plotvalues),
    > PlotBy:= _ xlColumns
    >
    > End Sub()
    >
    > Please help!
    >




  3. #3
    peabrain25
    Guest

    RE: macro calling another macro + variables

    Yo,

    You need to pass the variable to the next Sub. Try this...

    Sub datasplit()

    plotvalues = ActiveSheet.Range("A1:L15").Address

    Call Macroplot(plotvalues) 'add the variable name here in ()
    End Sub


    Sub Macroplot(plotvalues) 'add the variable name here in ()

    'keep the rest of your code as it is.

    End Sub


    Hope that helps!

    Mark


    "yo" wrote:

    > I am trying to call another macro plot within a main macro that chooses data.
    > I define a range "plotvalues" in the main macro and the second macro plots
    > "plotvalues." However, the variable is not being recognized. here is the
    > gist of what my code is like.
    >
    > Sub datasplit()
    > ....
    > plotvalues = ActiveSheet.Range("A1:L15").Address
    >
    > Macroplot
    > End Sub()
    >
    > Sub Macroplot()
    > Charts.Add
    > ActiveChart.ChartType = xlXYScatter
    > ActiveChart.SetSourceData Source:=Sheets("Input").Range(plotvalues),
    > PlotBy:= _ xlColumns
    >
    > End Sub()
    >
    > Please help!
    >


+ 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