Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 177
Default Auto Scale Chart Macro -- Any improvements please?

This is the best way I've found to correctly scale a chart -- the only way I
found to exclude a chart interpolating with #NA cells was to delete those
cells containing #NA, and run the chart. This takes a long time on my
computer. Wondering if there is a better way. This macro is directly taken
from 2 excel mvps and modified; i believe a mehta and ron bovarty, but could
be wrong. Thanks for taking a look.

Sub AutoScaleYAxes()
Dim ValuesArray(), SeriesValues As Variant
Dim Ctr As Integer, TotCtr As Integer

Application.Run "Extend_Stock_Data"
Application.Run "Delete_Row_NA_Data"

Sheets("SnapShot").Select
ActiveSheet.ChartObjects("CIQChart1s0t0").Activate
ActiveChart.PlotArea.Select
ActiveWindow.Visible = False

With ActiveChart
On Error Resume Next
For Each X In .SeriesCollection
SeriesValues = X.Values
ReDim Preserve ValuesArray(1 To TotCtr + UBound(SeriesValues))
For Ctr = 1 To UBound(SeriesValues)
ValuesArray(Ctr + TotCtr) = SeriesValues(Ctr)
Next
TotCtr = TotCtr + UBound(SeriesValues)
Next
.Axes(xlValue).MinimumScaleIsAuto = True
.Axes(xlValue).MaximumScaleIsAuto = True
.Axes(xlValue).MinimumScale = Application.Min(ValuesArray)
.Axes(xlValue).MaximumScale = Application.Max(ValuesArray)
End With
End Sub


Sub Delete_Row_NA_Data()
Dim DeleteValue As String
Dim rng As Range

Sheets("data").Select
DeleteValue = "#N/A"
With ActiveSheet
.Range("D100:D1000").AutoFilter Field:=1, Criteria1:=DeleteValue
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete

End With
.AutoFilterMode = False
End With
End Sub

Sub Extend_Stock_Data()


Dim LastRow As Long


With Worksheets("data")
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
..Range("b17:g17").AutoFill Destination:=.Range("b17:g" & LastRow) _
, Type:=xlFillDefault

End With

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 3,365
Default Auto Scale Chart Macro -- Any improvements please?

I'm betting that the code is about as good as it gets. I just finished a
battle with 2007 charts also, and kind of feel like I lost <g. You said "it
takes a long time on my computer" and that's exactly the experience I had:
charting on two separate systems takes up to 12 times as long in Excel 2007
to complete as it does for same data and same chart type in Excel 2003 on a
machine much slower than either of the two running 2007.

To give specifics: generating 51 charts, 49 with 8800 data points, 2 with
1320 data points. X-Y Scatter chart.
AMD 3200+ 1GB single core w/Excel 2003: 1m 21s to complete
AMD X2 4800+ 2GB dual-core w/Excel 2007: 12m 05s to complete!
Intel E6600 2GB 'CoreDuo' w/Excel 2007: 11m 47s to complete!

After finishing the charting, system response in Excel is snail-slow.

Also, are you seeing anything during the changing of the charts with
ActiveWindow.Visible=False ??
I was using Application.ScreenUpdating=False and the charting process forces
its way through that in Excel 2007, where it did not in 2003.

"SteveC" wrote:

This is the best way I've found to correctly scale a chart -- the only way I
found to exclude a chart interpolating with #NA cells was to delete those
cells containing #NA, and run the chart. This takes a long time on my
computer. Wondering if there is a better way. This macro is directly taken
from 2 excel mvps and modified; i believe a mehta and ron bovarty, but could
be wrong. Thanks for taking a look.

Sub AutoScaleYAxes()
Dim ValuesArray(), SeriesValues As Variant
Dim Ctr As Integer, TotCtr As Integer

Application.Run "Extend_Stock_Data"
Application.Run "Delete_Row_NA_Data"

Sheets("SnapShot").Select
ActiveSheet.ChartObjects("CIQChart1s0t0").Activate
ActiveChart.PlotArea.Select
ActiveWindow.Visible = False

With ActiveChart
On Error Resume Next
For Each X In .SeriesCollection
SeriesValues = X.Values
ReDim Preserve ValuesArray(1 To TotCtr + UBound(SeriesValues))
For Ctr = 1 To UBound(SeriesValues)
ValuesArray(Ctr + TotCtr) = SeriesValues(Ctr)
Next
TotCtr = TotCtr + UBound(SeriesValues)
Next
.Axes(xlValue).MinimumScaleIsAuto = True
.Axes(xlValue).MaximumScaleIsAuto = True
.Axes(xlValue).MinimumScale = Application.Min(ValuesArray)
.Axes(xlValue).MaximumScale = Application.Max(ValuesArray)
End With
End Sub


Sub Delete_Row_NA_Data()
Dim DeleteValue As String
Dim rng As Range

Sheets("data").Select
DeleteValue = "#N/A"
With ActiveSheet
.Range("D100:D1000").AutoFilter Field:=1, Criteria1:=DeleteValue
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete

End With
.AutoFilterMode = False
End With
End Sub

Sub Extend_Stock_Data()


Dim LastRow As Long


With Worksheets("data")
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
.Range("b17:g17").AutoFill Destination:=.Range("b17:g" & LastRow) _
, Type:=xlFillDefault

End With

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 6,582
Default Auto Scale Chart Macro -- Any improvements please?

This can be cleaned up:

Sheets("SnapShot").Select
ActiveSheet.ChartObjects("CIQChart1s0t0").Activate
ActiveChart.PlotArea.Select
ActiveWindow.Visible = False

With ActiveChart

use this instead:

With Sheets("SnapShot").ChartObjects("CIQChart1s0t0")

I don't know how much it will help with 2007. I have yet to do any
large-scale charting in 2007, just small bits to find workarounds for one of
my clients.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"SteveC" wrote in message
...
This is the best way I've found to correctly scale a chart -- the only way
I
found to exclude a chart interpolating with #NA cells was to delete those
cells containing #NA, and run the chart. This takes a long time on my
computer. Wondering if there is a better way. This macro is directly
taken
from 2 excel mvps and modified; i believe a mehta and ron bovarty, but
could
be wrong. Thanks for taking a look.

Sub AutoScaleYAxes()
Dim ValuesArray(), SeriesValues As Variant
Dim Ctr As Integer, TotCtr As Integer

Application.Run "Extend_Stock_Data"
Application.Run "Delete_Row_NA_Data"

Sheets("SnapShot").Select
ActiveSheet.ChartObjects("CIQChart1s0t0").Activate
ActiveChart.PlotArea.Select
ActiveWindow.Visible = False

With ActiveChart
On Error Resume Next
For Each X In .SeriesCollection
SeriesValues = X.Values
ReDim Preserve ValuesArray(1 To TotCtr + UBound(SeriesValues))
For Ctr = 1 To UBound(SeriesValues)
ValuesArray(Ctr + TotCtr) = SeriesValues(Ctr)
Next
TotCtr = TotCtr + UBound(SeriesValues)
Next
.Axes(xlValue).MinimumScaleIsAuto = True
.Axes(xlValue).MaximumScaleIsAuto = True
.Axes(xlValue).MinimumScale = Application.Min(ValuesArray)
.Axes(xlValue).MaximumScale = Application.Max(ValuesArray)
End With
End Sub


Sub Delete_Row_NA_Data()
Dim DeleteValue As String
Dim rng As Range

Sheets("data").Select
DeleteValue = "#N/A"
With ActiveSheet
.Range("D100:D1000").AutoFilter Field:=1, Criteria1:=DeleteValue
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete

End With
.AutoFilterMode = False
End With
End Sub

Sub Extend_Stock_Data()


Dim LastRow As Long


With Worksheets("data")
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
.Range("b17:g17").AutoFill Destination:=.Range("b17:g" & LastRow) _
, Type:=xlFillDefault

End With

End Sub



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 to draw chart: log scale on X axis, natural scale on y axis? Pratap D. chavan Charts and Charting in Excel 1 November 16th 06 08:03 AM
Urgent - X and Y Axis Auto Scale for Chart Sandi Charts and Charting in Excel 3 June 9th 06 09:04 AM
XY Chart Improvements For Scientific Data Phil Preen Charts and Charting in Excel 3 October 15th 05 04:33 AM
Changing a chart scale using a formula/macro Doug Charts and Charting in Excel 2 August 10th 05 10:45 PM
Chart Axis Scale Auto Values Moses Bunting Charts and Charting in Excel 1 June 7th 05 11:03 PM


All times are GMT +1. The time now is 02:51 AM.

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"