RawlinsCross
Active Member
- Joined
- Sep 9, 2016
- Messages
- 437
Good day. I have a userform with approximately 50 labels each containing a number which is the latest number in a column of numbers (i.e. I have 50 columns and say 365 rows). I have a code that calls another userform which has a graph when you click on any of the 50 labels (see code below).
So the long of it is - I don't want to make 50 separate userforms for each of the labels. I'd like to have just one userform containing the code (see below again) that accepts arguments for things like axis title, MinimumScale, NumberFormat, .Range - things like that. How is this done?
So the long of it is - I don't want to make 50 separate userforms for each of the labels. I'd like to have just one userform containing the code (see below again) that accepts arguments for things like axis title, MinimumScale, NumberFormat, .Range - things like that. How is this done?
Code:
Private Sub UserForm_Initialize()
Dim MyChart As Chart
Dim ChartData As Range
Dim ChartName As String
Application.ScreenUpdating = False
Worksheets("Dashboard").Range("H4").Value = ActiveWindow.Zoom
ActiveWindow.Zoom = 85
Set ChartData = Worksheets("Main Element Profiles").Range("Y7:Y37")
ActiveSheet.Range("B2").Select
Set MyChart = ActiveSheet.Shapes.AddChart(xlXYScatterLines).Chart
With MyChart
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = ChartName
.SeriesCollection(1).Values = ChartData
.SeriesCollection(1).XValues = Worksheets("Main Element Profiles").Range("B7:B37")
.Legend.Select
Selection.Delete
.Axes(xlCategory).Select
Selection.TickLabels.NumberFormat = "m/d/yyyy"
Selection.TickLabels.NumberFormat = "[$-409]mmm-dd;@"
.Axes(xlValue).Select
Selection.TickLabels.NumberFormat = "#,##0.00"
Selection.TickLabels.NumberFormat = "#,##0.0,"
.Axes(xlValue).HasTitle = True
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).AxisTitle.Text = "Na Concentration (g/L)"
End With
Dim ImageName As String
ImageName = Application.DefaultFilePath & Application.PathSeparator & "TempChart.jpeg"
MyChart.Export filename:=ImageName
ActiveSheet.ChartObjects(1).Delete
ActiveWindow.Zoom = Worksheets("Dashboard").Range("H4").Value
Application.ScreenUpdating = True
ASSAY221FLASH2NA.Image1.Picture = LoadPicture(ImageName)
End Sub