Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
scmancl21
 
Posts: n/a
Default How do I scale excel chart axes from vb?

Is there a way to change the axis scale of an existing chart in an excel
spreadsheet from vb code?

Thanks,
Scott
  #2   Report Post  
bj
 
Posts: n/a
Default

If you can change it while you look at it you can change it with a macro.

What Kind of chart is it?
is it the X, Y or Z axis you wish to change?

I would first try to record a macro of me trying to change it the way You
want it changed and then go from there.
"scmancl21" wrote:

Is there a way to change the axis scale of an existing chart in an excel
spreadsheet from vb code?

Thanks,
Scott

  #3   Report Post  
John Mansfield
 
Posts: n/a
Default

Yes, you can. Please see Jon's explanation:

http://www.peltiertech.com/Excel/Cha...nkToSheet.html

Here are some more examples:

'(1) Embedded chart - sets primary axis based on hardcoded inputs:

Sub SetAxes1()
Dim Cht As Chart
Set Cht = Sheets("Sheet1").ChartObjects("Cht01").Chart
With Cht.Axes(xlValue)
.MaximumScale = 6
.MinimumScale = 1
.MajorUnit = 0.5
End With
End Sub

'(2) Embedded chart - sets primary axis based on worksheet cell inputs:

Sub SetAxes2()
Dim Cht As Chart
Set Cht = Sheets("Sheet1").ChartObjects("Cht01").Chart
With Cht.Axes(xlValue)
.MaximumScale = Range("A1")
.MinimumScale = Range("A2")
.MajorUnit = Range("A3")
End With
End Sub

'(3) Embedded chart - sets primary and secondary axis based on worksheet
cell inputs

Sub SetAxes3()
Dim Cht As Chart
Set Cht = Sheets("Sheet1").ChartObjects("Cht01").Chart
With Cht.Axes(xlValue, xlPrimary)
.MaximumScale = Range("A1")
.MinimumScale = Range("A2")
.MajorUnit = Range("A3")
End With
With Cht.Axes(xlValue, xlSecondary)
.MaximumScale = Range("B1")
.MinimumScale = Range("B2")
.MajorUnit = Range("B3")
End With
End Sub

'(4) Chart sheet set axis

Sub SetAxes4()
Dim Cht As Chart
Set Cht = Sheets("Chart1")
With Cht.Axes(xlValue)
.MaximumScale = Range("A1")
.MinimumScale = Range("A2")
.MajorUnit = Range("A3")
End With
End Sub

--
Regards,
John Mansfield
http://www.pdbook.com


"scmancl21" wrote:

Is there a way to change the axis scale of an existing chart in an excel
spreadsheet from vb code?

Thanks,
Scott

  #4   Report Post  
Tushar Mehta
 
Posts: n/a
Default

From inside of XL turn on the macro recorder (Tools | Macro Record
new macro...) do whatever you want using the UI, and turn off the
recorder. XL will give you the necessary code which you will have to
tailor to your specific needs.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Is there a way to change the axis scale of an existing chart in an excel
spreadsheet from vb code?

Thanks,
Scott

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I eliminate duplicate values on y axis of an Excel chart? Paul Charts and Charting in Excel 1 March 24th 05 04:26 AM
How can I print an excel chart so a picture is not distorted? MJADAMS Charts and Charting in Excel 0 February 9th 05 03:03 PM
Excel chart like the FTSE chart Charts and Charting in Excel 0 February 9th 05 02:26 PM
i can't open excel workbook if it has a chart in it! Aidan Excel Discussion (Misc queries) 2 February 2nd 05 09:37 AM
3D Chart with Continuous Data in all three Axes Barb Reinhardt Charts and Charting in Excel 3 January 10th 05 07:09 PM


All times are GMT +1. The time now is 04:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"