Chart on Userform

urobee

Board Regular
Joined
Jan 30, 2015
Messages
98
Hy, I have the following code to put a chart on a userform with multipage:

Code:
Function chart_v1()LoadSheets
Dim MyChart As chart
Dim ChartData, ChartData2 As Range
Dim chartIndex As Integer
Dim ChartName, ChartName2 As String
Dim i As Long


chartIndex = MultiPage1.Value
Select Case chartIndex


Case 0


Set ChartData = ShSPC0.Range("B40:AE40")
ChartName = ShSPC0.Range("H3")
Set ChartData2 = ShSPC0.Range("B35:AE35")
ChartName2 = ShSPC0.Range("A35")


'''....more cases


End Select


Application.ScreenUpdating = False


Set MyChart = ShJou.Shapes.AddChart(xlXYScatterLines).chart


With MyChart
    Do While .SeriesCollection.Count > 0
        .SeriesCollection(1).Delete
    Loop
End With




MyChart.SeriesCollection.NewSeries
MyChart.SeriesCollection(1).Name = ChartName
MyChart.SeriesCollection(1).Values = ChartData
MyChart.SeriesCollection(1).XValues = ShJou.Range("A9:A38")


MyChart.SeriesCollection.NewSeries
MyChart.SeriesCollection(2).Name = ChartName2
MyChart.SeriesCollection(2).Values = ChartData2
MyChart.SeriesCollection(2).XValues = ShJou.Range("A9:A38")


With ShJou.ChartObjects(1)
        .Height = 300
        .Width = 935
End With


Dim imageName As String
imageName = Application.DefaultFilePath & Application.PathSeparator & "TempChart.gif"
MyChart.Export Filename:=imageName, FilterName:="GIF"


ShJou.ChartObjects(1).Delete


Application.ScreenUpdating = True






v1.Image1.Picture = LoadPicture(imageName)
'''....more pictures to show




End Function


The chart is appering, but instead of the needed 30 values on the scale of the X-Axis it is show 35 values.
(this part in the code: XValues = ShJou.Range("A9:A38")

The ChartData is working right, it is show only 30 values.

What should I modify in the code?
Thank You!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I've tried to modify the data range and the range of the scale too, but the plus 5 number in the scale is still appear..
 
Upvote 0
I found the solution:
(Maybe it will be a help for somebody in the future)
Code:
MyChart.Axes(xlCategory).MaximumScale = 30

Macro Record sometimes a really good friend :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top