UPDATE 2: Trying to define the Variable with the column range in the VBA. Can anyone guess what's wrong in this code ? Thanks in advance...
UPDATE 1: I have been successful in generating the chart. Thanks to you guys for the constructive criticism. I'm a newbie to VBA, just learning :) My challenge now is to define the row selected for the graph as a variable.
ie. The user gives an input for the ROW and the macro generates the chart for the intended Row.
Find the UPDATED CODE BELOW. Thanks to all
I need to write a macro to create a individual performance chart in Excel. I have a few lines of code recorded, but the resultant chart does not have any labels on the X & Y Axis.
My requirement is to create a chart with the following features:
- Option to choose the row no. in the beginning of the macro (for which row the chart needs to be prepared) - some input box
- Comparison Feature to compare Row 1 with Row 2. (some input box)
- Data Series Label (X Axis)
- Chart Title
MY EXCEL LOOKS LIKE THIS:
Sales Achieved |Clients Met| Client Responsiveness|
Employee 1 | 6 | 7 | 8 |
Employee 2 | 6 | 7 | 8 |
Employee 3 | 6 | 7 | 8 |
Employee 4 | 6 | 7 | 8 |
Sub generatecharts()
Dim xValRange As Range
Dim r
r = irow
irow = InputBox("Which Chart do you want to generate?")
With ActiveSheet
Set xValRange = ActiveSheet.Range("B" & r & ":" & "Q" & r)
End With
With ActiveSheet
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Values = xValRange
ActiveChart.SeriesCollection(1).XValues = "=Sheet2!$B$1:$Q$2"
ActiveChart.SeriesCollection(1).Name = "=Sheet2!$A$" & r
With ActiveChart.Parent
.Height = 400
.Width = 800
End With
End With
End Sub