Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

excel vba charts

ResolvedVersion 2003

Michael has attended:
Excel Advanced course
Excel VBA Intro Intermediate course
Access VBA course

Excel VBA - Charts

Is it possible to amend the 'source data' range with VBA when constructing/updating excel charts ?

RE: Excel VBA - Charts

Hi Michael,

Thank you for your question. Whenever you wish to change any data, you should set it as a Variable. In this case, SourceData should be set as a range variable.

Assuming your sourcedata always start in cell "A1" of worksheet "Sheet 1", see the sample codes below:

====================================
Sub MakeChart()

Dim SourceData As Range

Set SourceData = Range("A1", Range("A1").End(xlToRight).End(xlDown))

Charts.Add

ActiveChart.SetSourceData Source:=SourceData
ActiveChart.Location Where:=xlLocationAsNewSheet

Sheets("Sheet1").Select

End sub

====================================

Hope this is useful

Kind regards,

Katie Woo
Microsoft Certified Trainer

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Selecting constant values only

If periodically you need to change all your values back to zero, but leave formulas, text and blank cells as they are select the entire worksheet, choose F5 function key, Special and then Constants and choose the appropriate sub-selections. To enter zero in all the selected cells type 0 and then press Ctrl+Enter.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.