ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   chart MAcro to change on activecell (https://www.excelbanter.com/excel-discussion-misc-queries/59196-chart-macro-change-activecell.html)

flow23

chart MAcro to change on activecell
 
Here is the macro below.. The only problem is that the columns change every
month. so range (columns)keeps widening.... I have sorted it by selecting
range upto column N. so it is provided for all 12 months.
But now the "Grand total" column which is always the last column also gets
included..(.which shouldnt be included in the range for the chart)

Is there a way to modify this macro ?

Sub updatechart1()
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("summary").CheckBox1 Then
Set ThechartObj = ActiveSheet.ChartObjects(1)
Set Thechart = ThechartObj.Chart
Userrow = ActiveCell.Row

If Userrow < 20 Or IsEmpty(Cells(Userrow, 1)) Then
ThechartObj.Visible = False

Else

Set CatTitles = Range("A20:N20")
Set SrcRange = Range(Cells(Userrow, 1), _
Cells(Userrow, 14))

Set SourceData = Union(CatTitles, SrcRange)
Thechart.SetSourceData _
Source:=SourceData, PlotBy:=xlRows

Thechart.SeriesCollection(1).XValues = "=summary!R20C2:R20C14"


ThechartObj.Visible = True
End If
End If

End Sub


All times are GMT +1. The time now is 05:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com