Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Change Source Data in VBA


Hi,

Please be aware that I have also posted this in the XL Charts group as I am
not sure which is most appropriate.

I have a chart set up (eg a simple bar chart) that I want to be able to
update automatically using VBA. The source data will vary in quantity and I
have no way of knowing in advance how many data there will be.
Eg
I might currently have:
A1 B1 C1 D1
10 12 15 35

but when I want to refresh the chart I might have:
A1 B1 C1 D1 E1 F1
15 5 10 20 25 10

(don't worry about the actual values).

How do I tell Excel to re-size the source data area automatically (ie as
part of a VBA macro) - the number of data may reduce as well as increase?

I'm reasonalby comfortable with VBA but by no means am I a programmer, so a
brief explanation of how the solution works would be appreciated.

This is in Office 2003 if that makes a difference.

TIA

Dave

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Change Source Data in VBA

You need to find the chart name. I added code to help you find the name.
You also have to get the range of address which a named SourceRange. Chart
object a very particular about activating before being able to change an
item. the code below is very simple and you should easily be able to
understand. Just don't question the format. Just accept this what is
required.

For Each chrt In ActiveSheet.ChartObjects
MsgBox (chrt.Name)
Set mychart = chrt
Next chrt
Set LastCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft)
Set SourceRange = Range(Range("A1"), LastCol)


With mychart
.Activate
ActiveChart.ChartArea.Select
ActiveChart.SetSourceData Source:=SourceRange, PlotBy:=xlRows
End With

"Risky Dave" wrote:

Hi,

Please be aware that I have also posted this in the XL Charts group as I am
not sure which is most appropriate.

I have a chart set up (eg a simple bar chart) that I want to be able to
update automatically using VBA. The source data will vary in quantity and I
have no way of knowing in advance how many data there will be.
Eg
I might currently have:
A1 B1 C1 D1
10 12 15 35

but when I want to refresh the chart I might have:
A1 B1 C1 D1 E1 F1
15 5 10 20 25 10

(don't worry about the actual values).

How do I tell Excel to re-size the source data area automatically (ie as
part of a VBA macro) - the number of data may reduce as well as increase?

I'm reasonalby comfortable with VBA but by no means am I a programmer, so a
brief explanation of how the solution works would be appreciated.

This is in Office 2003 if that makes a difference.

TIA

Dave

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Change Source Data in VBA


you may not need VBA to resolve. Have a look at this site:

http://peltiertech.com/Excel/Charts/Dynamics.html
--
jb


"Risky Dave" wrote:

Hi,

Please be aware that I have also posted this in the XL Charts group as I am
not sure which is most appropriate.

I have a chart set up (eg a simple bar chart) that I want to be able to
update automatically using VBA. The source data will vary in quantity and I
have no way of knowing in advance how many data there will be.
Eg
I might currently have:
A1 B1 C1 D1
10 12 15 35

but when I want to refresh the chart I might have:
A1 B1 C1 D1 E1 F1
15 5 10 20 25 10

(don't worry about the actual values).

How do I tell Excel to re-size the source data area automatically (ie as
part of a VBA macro) - the number of data may reduce as well as increase?

I'm reasonalby comfortable with VBA but by no means am I a programmer, so a
brief explanation of how the solution works would be appreciated.

This is in Office 2003 if that makes a difference.

TIA

Dave

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Change Source Data in VBA


Hi, I replied to this a few minutes ago but it hasn't appeared (I've got an
ongoing problem using this discussion group, perhaps to do with my using the
non-M/soft Firefox browser) so I'll repost in case. I think the best
solution is to name the ranges for your x-data and any y-series. Then you
can use these names in your chart series data itself and you won't actually
need VBA at all if you're careful to only insert new data within the range
names.

"Risky Dave" wrote:

Hi,

Please be aware that I have also posted this in the XL Charts group as I am
not sure which is most appropriate.

I have a chart set up (eg a simple bar chart) that I want to be able to
update automatically using VBA. The source data will vary in quantity and I
have no way of knowing in advance how many data there will be.
Eg
I might currently have:
A1 B1 C1 D1
10 12 15 35

but when I want to refresh the chart I might have:
A1 B1 C1 D1 E1 F1
15 5 10 20 25 10

(don't worry about the actual values).

How do I tell Excel to re-size the source data area automatically (ie as
part of a VBA macro) - the number of data may reduce as well as increase?

I'm reasonalby comfortable with VBA but by no means am I a programmer, so a
brief explanation of how the solution works would be appreciated.

This is in Office 2003 if that makes a difference.

TIA

Dave

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Source Data in VBA Risky Dave Charts and Charting in Excel 1 November 9th 09 02:38 PM
Problem when trying to change source data Beverly Darvill[_2_] Charts and Charting in Excel 4 October 1st 09 03:19 PM
how do i change the data source derwood[_2_] Excel Discussion (Misc queries) 2 December 27th 07 04:12 PM
Is there a way to keep the formulas and change their source data? Shannon Excel Discussion (Misc queries) 3 May 22nd 06 08:01 PM
Change Data Source Alfred[_3_] Excel Programming 3 September 21st 04 07:41 AM


All times are GMT +1. The time now is 09:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"