Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.charting,microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Macro to create charts?

I recorded a macro to create charts using the Wizard, but ran into a
problem. My X-axis is in Col. A. The label is in A1, and the data starts
in A5 (time). I modified the macro to use the last data row, and I also
modified it to use other ranges for data, keeping Col A as my X-axis. This
version, though, gave me fits on one particular sheet.

Cols B - J are data to be plotted by the lines in the chart. On one
worksheet, however, the sensor for the Col B data didn't record, and the
recorder program filled the column with "NONE". The Wizard and the macro
*insisted* on grouping A and B together for my X-axis on this sheet, though
it worked okay for the other sheets. Looking at the macro, I realized there
isn't anything (that I can see) that specifies which column is the X-axis

Is there a better way to write this?

Ed

Sub Macro9()
'
Dim LastRow As Long
LastRow = ActiveWorkbook.Sheets("Sheet1").Range("A65536").En d(xlUp).Row


Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range( _
"A1,B1:J1,A5:A" & LastRow & ",B5:J" & LastRow), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.charting,microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Macro to create charts?

Ed -

Omit the SetSourceData command. Instead, add each series and set its source
data separately:

Sub DoChart()
Dim LastRow As Long
Dim iSrs As Long
LastRow = 10

With Charts.Add
' Remove Extraneous Series
Do While .SeriesCollection.Count 0
.SeriesCollection(1).Delete
Loop
.ChartType = xlLine
' Add Series
For iSrs = 1 To 9
With .SeriesCollection.NewSeries
.Values = Sheets("Sheet1").Range("A5:A" & LastRow).Offset(, iSrs)
.XValues = Sheets("Sheet1").Range("A5:A" & LastRow)
.Name = Sheets("Sheet1").Range("A1").Offset(, iSrs)
End With
Next
End With

End Sub

More on VBA charting:

http://peltiertech.com/Excel/ChartsH...kChartVBA.html

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


"Ed" wrote in message
...
I recorded a macro to create charts using the Wizard, but ran into a
problem. My X-axis is in Col. A. The label is in A1, and the data starts
in A5 (time). I modified the macro to use the last data row, and I also
modified it to use other ranges for data, keeping Col A as my X-axis. This
version, though, gave me fits on one particular sheet.

Cols B - J are data to be plotted by the lines in the chart. On one
worksheet, however, the sensor for the Col B data didn't record, and the
recorder program filled the column with "NONE". The Wizard and the macro
*insisted* on grouping A and B together for my X-axis on this sheet,
though it worked okay for the other sheets. Looking at the macro, I
realized there isn't anything (that I can see) that specifies which column
is the X-axis

Is there a better way to write this?

Ed

Sub Macro9()
'
Dim LastRow As Long
LastRow = ActiveWorkbook.Sheets("Sheet1").Range("A65536").En d(xlUp).Row


Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range( _
"A1,B1:J1,A5:A" & LastRow & ",B5:J" & LastRow), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.charting,microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Macro to create charts?

Thank you, Jon. I appreciate the help.
Ed

"Jon Peltier" wrote in message
...
Ed -

Omit the SetSourceData command. Instead, add each series and set its
source data separately:

Sub DoChart()
Dim LastRow As Long
Dim iSrs As Long
LastRow = 10

With Charts.Add
' Remove Extraneous Series
Do While .SeriesCollection.Count 0
.SeriesCollection(1).Delete
Loop
.ChartType = xlLine
' Add Series
For iSrs = 1 To 9
With .SeriesCollection.NewSeries
.Values = Sheets("Sheet1").Range("A5:A" & LastRow).Offset(, iSrs)
.XValues = Sheets("Sheet1").Range("A5:A" & LastRow)
.Name = Sheets("Sheet1").Range("A1").Offset(, iSrs)
End With
Next
End With

End Sub

More on VBA charting:

http://peltiertech.com/Excel/ChartsH...kChartVBA.html

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


"Ed" wrote in message
...
I recorded a macro to create charts using the Wizard, but ran into a
problem. My X-axis is in Col. A. The label is in A1, and the data starts
in A5 (time). I modified the macro to use the last data row, and I also
modified it to use other ranges for data, keeping Col A as my X-axis.
This version, though, gave me fits on one particular sheet.

Cols B - J are data to be plotted by the lines in the chart. On one
worksheet, however, the sensor for the Col B data didn't record, and the
recorder program filled the column with "NONE". The Wizard and the macro
*insisted* on grouping A and B together for my X-axis on this sheet,
though it worked okay for the other sheets. Looking at the macro, I
realized there isn't anything (that I can see) that specifies which
column is the X-axis

Is there a better way to write this?

Ed

Sub Macro9()
'
Dim LastRow As Long
LastRow = ActiveWorkbook.Sheets("Sheet1").Range("A65536").En d(xlUp).Row


Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range( _
"A1,B1:J1,A5:A" & LastRow & ",B5:J" & LastRow), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
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 create a command button, then assign macro to it in excel kshaheen Excel Discussion (Misc queries) 3 June 24th 08 01:03 PM
Please Help Me with Custom menus Mr BT Excel Worksheet Functions 7 July 4th 06 05:15 PM
Using a macro to create a macro in another workbook Gizmo63 Excel Worksheet Functions 2 May 15th 06 09:48 AM
How do I create a macro that will compare columns and place data CompuCat Excel Worksheet Functions 0 March 20th 06 06:21 PM
Macro for multiple charts JS Excel Worksheet Functions 1 November 19th 04 03:44 AM


All times are GMT +1. The time now is 06:06 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"