Linking dynamically allocated row offset to stacked column chart data range variable

amanagarwal

New Member
Joined
Jul 5, 2011
Messages
2
Hi,

Thank you for looking into this problem.

I have a workbook in which I have a summary sheet of all the data/calculations I need to refer-to/make-use-of in order to analyze some key pointers. I am using VBA to dynamically allocate a certain number of rows (ModuleStability) in that summary sheet and then populate those rows with data from other worksheets in my workbook with the help of another macro. I have created a stacked column chart to compare two things and the problem I was facing was that I needed to update that chart based on this new data that I populated the rows with. I wrote the below-mentioned macro to select/update the chart's data range. Now, the problem I'm facing with this is that while I can concretely define numbers for range extremes, I can't seem to figure out how to abstractly tell excel to set the source data for the chart to row:4 through (allocated variable) and column:C F G are used.

The actual code for the chart itself starts on line 13 (excluding blank lines), and everything before that (Line 1-12) is for summarizing/aggregating the rows that I populated with the previous macro I used. Clearly, I have had success with the summarizing even though there is a dynamically allocated variable (ModuleStability) involved with it's calculations but fail to do so with the chart. After reading through forums for a week and trying out different things, I have given up and finally posted on here. So any help would be really appreciated and am ready to get flamed for mistakes since this would be my first time posting.


Sub CalculatingStabilityRisk()
'
' CalculatingStabilityRisk Macro
'
ModuleStability = InputBox("Enter the number of modules including Module 1", "Number of modules", 1) 'Typically user would enter 5 or 6 and then it will drop down 5 rows, the implementation of which takes place in another macro
ModuleStability = ModuleStability + 4 'Since calculations will start from row 4
Range("D" & ModuleStability).Select
R1 = ActiveCell.Row
ActiveCell.Value = Application.Sum(Range(Cells(4, 4), Cells(R1 - 1, 4)))
ActiveCell.Value = Application.Sum(Range(Cells(4, 4), Cells(R1 - 1, 4)))
Range("E" & ModuleStability).Select
R2 = ActiveCell.Row
ActiveCell.Value = Application.Sum(Range(Cells(4, 5), Cells(R2 - 1, 5)))
ActiveCell.Value = Application.Sum(Range(Cells(4, 5), Cells(R2 - 1, 5)))

'(RowOffset has a -1 is since there exists one row by default)
RowOffset = ModuleStability - 1
Set ChartRange.Value = Sheets("Summary").Range(Cells(3, 3), Cells(RowOffset, 3))
ActiveSheet.ChartObjects("Chart 17").Activate
ActiveChart.SetSourceData Source:=ChartRange.Value
End Sub

'I also would typically want the chart range above to include Cells(3, 6) to (RowOffset, 6) for column F and Cells(3, 7) to (RowOffset, 7) for column G but whatever I have seems to be buggy.

Thank you once again!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Really need some help here. If someone wants to just point the problem and not write VBA, that's fine too. I just have never used VBA before hence not sure of syntax alot.
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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