LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Loop to create charts

Hey all,

I have about 50 columns of data and need to create a chart for each column. Currently
I am writing separate macro for each column. The only thing that really changes is the
chart name, source data range, and series collection name. How can I write a loop to create
a chart for each column of data?

Thanks in advance

Lance


For i = 2 to 50
Charts.Add
ActiveChart.ChartType = xlBarClustered
ActiveChart.Location Whe=xlLocationAsNewSheet
'
'''
''' Not certain how to change this for a loop - this gives an error
ActiveChart.SetSourceData Source:=Sheets("Data").Range("Cells(2,i),Cells(13, i)), PlotBy:=xlColumns
'''
''' Not certain how to change this for a loop
ActiveChart.SeriesCollection(1).Name = "=Data!R1C3"

'
ActiveChart.SeriesCollection(1).XValues = "=Data!R2C1:R13C1"
ActiveChart.HasLegend = False
ActiveChart.ApplyDataLabels ShowValue:=True
ActiveChart.Deselect
Sheets(iCName).Move After:=Worksheets(Worksheets.Count)
Next i



Sub S1B2()
iCName = "S1B2"
Charts.Add
ActiveChart.ChartType = xlBarClustered
ActiveChart.Location Whe=xlLocationAsNewSheet
'
ActiveChart.SetSourceData Source:=Sheets("Data").Range("C2:C13"), PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).Name = "=Data!R1C3"
ActiveChart.Name = iCName
'
ActiveChart.SeriesCollection(1).XValues = "=Data!R2C1:R13C1"
ActiveChart.HasLegend = False
ActiveChart.ApplyDataLabels ShowValue:=True
ActiveChart.Deselect
Sheets(iCName).Move After:=Worksheets(Worksheets.Count)
End Sub
Sub S1B3()
iCName = "S1B3"
Charts.Add
ActiveChart.ChartType = xlBarClustered
ActiveChart.Location Whe=xlLocationAsNewSheet
'
ActiveChart.SetSourceData Source:=Sheets("Data").Range("D2:D13"), PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).Name = "=Data!R1C4"
ActiveChart.Name = iCName
'
ActiveChart.SeriesCollection(1).XValues = "=Data!R2C1:R13C1"
ActiveChart.HasLegend = False
ActiveChart.ApplyDataLabels ShowValue:=True
ActiveChart.Deselect
Sheets(iCName).Select
Sheets(iCName).Move After:=Sheets(Sheets.Count)
End Sub
 
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
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
Use a loop to create multiple Charts - Suggestions ? APOEL Charts and Charting in Excel 1 July 29th 06 03:36 AM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
How do I create a For loop within a For loop? Linking to specific cells in pivot table Excel Programming 2 January 24th 05 08:05 AM
Loop through sheets, deselect charts Daniel Bonallack[_2_] Excel Programming 4 October 28th 03 07:27 PM


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