Simple question from VBA noobie..
Hi,
for some reason I can not do this because I am new to VBA. How can I get a chart reference be made available in a userform?
I know module's is where you would want to declare global variables, but I still have a problem there.
In my spreadsheet:
VB Code:
Private sub transferChart()
Sheets("Sheet1").ChartObjects("Chart 1").Activate
Call toModule(ActiveChart)
End Sub
In Module:
VB Code:
Public Function toModule(ByVal mychart As Chart)
chartA = mychart
End Function
'userform would call this function to get the chart reference from spreadsheet
Public Function returnChart() As Chart
returnChart = chartA
End Function
this way seems kind of tedious. Is there another way, becuase this one isn't working.
Re: Simple question from VBA noobie..
btw, my chartA variable is a declared global variable in Module1.
I also have 'Set chartA = mychart' instead of 'chartA = mychart'
thanks!!
Re: Simple question from VBA noobie..
Code:
Private sub transferChart()
toModule Sheets("Sheet1").ChartObjects("Chart 1")
End Sub
Once you set it in the module, if you declare the variable to be public, you can just use that variable name from anycode in the forms modules or other modules directly. No need for a return function.