VBA to loop through columns and add series to Radar graph

Kaps_mr2

Well-known Member
Joined
Jul 5, 2008
Messages
1,589
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have data in columns in each sheet of a workbook.

I would like to set up a xlradar chart on each sheet - with each radar chart having multiple series. The data series are taken from data columns on the respective sheet. Here is my code - I can't seem to get it working:-

VBA Code:
Public Sub set_up_graphs()


Dim sh As Long
Dim sheet_name As String
Dim number_of_questions_in_this_category As Long
Dim chart_output_range As Range
Dim series_data_range As Range
Dim series_legend As String
Dim c As Long
Dim r As Long


Set chart_output_range = Range("b2:o16")


For sh = 1 To no_of_categories
    sheet_name = automater.Sheets(1).Range("g16").Offset(sh, 0)
    number_of_questions_in_this_category = automater.Sheets(1).Range("g16").Offset(sh, 2)
    
    
     With output_workbook.Sheets(sheet_name).ChartObjects.Add _
        (Left:=chart_output_range.Left, Width:=chart_output_range.Width, Top:=chart_output_range.Top, Height:=chart_output_range.Height)
        
        .Chart.ChartType = xlRadar
        .Chart.HasTitle = True
        
        .Chart.ChartTitle.Text = sheet_name
        .Chart.ChartTitle.Font.Size = 12
    End With
        
        
        For c = 1 To number_of_questions_in_this_category
        
         series_legend = output_workbook.Sheets(sheet_name).Range("o2").Offset(0, c).Value
                  
         Set series_data_range = output_workbook.Worksheets(sheet_name).Range("o1").Offset(last_row_of_source_data + 2, c).Resize(5, 1)
        
         With ActiveChart.SeriesCollection.NewSeries
         .XValues = series_data_range
         .Name = series_legend
        
         End With
    
    
        Next c
    
    Next sh
    


End Sub

can some one explain why pls ? thank you
,
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
What is actually happening? I don't see where you set last_row_of_source_data for starters.
 
Upvote 0
What is actually happening? I don't see where you set last_row_of_source_data for starters.
i get "object variable or with variable not set error 91" on :-

VBA Code:
With ActiveChart.SeriesCollection.NewSeries

last_row_of_source_data is set as a public variable. thank you
 
Upvote 0
Use a chart variable:

VBA Code:
dim ch as chart
     set ch = output_workbook.Sheets(sheet_name).ChartObjects.Add _
        (Left:=chart_output_range.Left, Width:=chart_output_range.Width, Top:=chart_output_range.Top, Height:=chart_output_range.Height).Chart
    with ch
        .ChartType = xlRadar
        .HasTitle = True
        .ChartTitle.Text = sheet_name
        .ChartTitle.Font.Size = 12
    End With

        For c = 1 To number_of_questions_in_this_category
        
         series_legend = output_workbook.Sheets(sheet_name).Range("o2").Offset(0, c).Value
                  
         Set series_data_range = output_workbook.Worksheets(sheet_name).Range("o1").Offset(last_row_of_source_data + 2, c).Resize(5, 1)
        
         With ch.SeriesCollection.NewSeries
         .XValues = series_data_range
         .Name = series_legend
        
         End With
    
    
        Next c
    
    Next sh
 
Upvote 0
Solution
Use a chart variable:

VBA Code:
dim ch as chart
     set ch = output_workbook.Sheets(sheet_name).ChartObjects.Add _
        (Left:=chart_output_range.Left, Width:=chart_output_range.Width, Top:=chart_output_range.Top, Height:=chart_output_range.Height).Chart
    with ch
        .ChartType = xlRadar
        .HasTitle = True
        .ChartTitle.Text = sheet_name
        .ChartTitle.Font.Size = 12
    End With

        For c = 1 To number_of_questions_in_this_category
       
         series_legend = output_workbook.Sheets(sheet_name).Range("o2").Offset(0, c).Value
                 
         Set series_data_range = output_workbook.Worksheets(sheet_name).Range("o1").Offset(last_row_of_source_data + 2, c).Resize(5, 1)
       
         With ch.SeriesCollection.NewSeries
         .XValues = series_data_range
         .Name = series_legend
       
         End With
   
   
        Next c
   
    Next sh
Many thanks.
 
Upvote 0
Please do not mark a post that doesn't contain a solution.

The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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