ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   macro calling another macro + variables (https://www.excelbanter.com/excel-discussion-misc-queries/81655-macro-calling-another-macro-variables.html)

yo

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!


Bernie Deitrick

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" wrote in message
...
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!




peabrain25

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!



All times are GMT +1. The time now is 03:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com