Active cell chart

R

Robert

Hi,

The following code updates a chart based on an active cell. In this
occasion he puts only one row into the chart. Now I would like to do
the same but then with 3 rows of data, say the line selected and the
following two rows.
Can someone tell me how to incorporate this in a code?

Thanks a lot!

Regards,
Robert


Sub UpdateChart()
Dim TheChartObj As ChartObject
Dim TheChart As Chart
Dim UserRow As Long
Dim CatTitles As Range
Dim SrcRange As Range
Dim SourceData As Range

If Sheets("Sheet1").CheckBox1 Then
Set TheChartObj = ActiveSheet.ChartObjects(1)
Set TheChart = TheChartObj.Chart
UserRow = ActiveCell.Row
If UserRow < 3 Or IsEmpty(Cells(UserRow, 1)) Then
TheChartObj.Visible = False
Else
Set CatTitles = Range("A2:W2")
Set SrcRange = Range(Cells(UserRow, 1), Cells(UserRow,
23))
Set SourceData = Union(CatTitles, SrcRange)
TheChart.SetSourceData _
Source:=SourceData, PlotBy:=xlRows
TheChartObj.Visible = True
End If
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top