Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-2008, 07:17 PM
Lars Uffmann
 
Posts: n/a
Add a new chart *without* default data?

Hi everyone!

I have a workbook in Excel 2003 with 2 worksheets with some ~6000 rows
each. Now I want to add some charts. On the first one, this seems to
work fine, and I set a bunch of properties (including the data source)
manually. Then when I add the 2nd chart, it predraws the whole thing
with all 6000 lines of data, even though I haven't yet defined any data
source. It just takes some default source and paints it. Of course this
is *very* annoying and unnecessarily slowing the whole thing down. Is
there any way to configure Excel so that a new chart will be a "naked"
chart, without attempting to display *any* data until I manually set up
a data source?

Grateful for any tips!

Lars
Reply With Quote
  #2 (permalink)  
Old 07-24-2008, 10:11 AM
Andy Pope
 
Posts: n/a
Re: Add a new chart *without* default data?

Hi,

You could try making sure the active cell is not within your data set.

Cheers
Andy

Lars Uffmann wrote:
> Hi everyone!
>
> I have a workbook in Excel 2003 with 2 worksheets with some ~6000 rows
> each. Now I want to add some charts. On the first one, this seems to
> work fine, and I set a bunch of properties (including the data source)
> manually. Then when I add the 2nd chart, it predraws the whole thing
> with all 6000 lines of data, even though I haven't yet defined any data
> source. It just takes some default source and paints it. Of course this
> is *very* annoying and unnecessarily slowing the whole thing down. Is
> there any way to configure Excel so that a new chart will be a "naked"
> chart, without attempting to display *any* data until I manually set up
> a data source?
>
> Grateful for any tips!
>
> Lars


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
Reply With Quote
  #3 (permalink)  
Old 07-24-2008, 11:25 AM
Lars Uffmann
 
Posts: n/a
Re: Add a new chart *without* default data?

Hi Andy,

Andy Pope wrote:
> You could try making sure the active cell is not within your data set.

Thank you, that did help me to understand where Excel is getting it's
data from. And it works. The "active cell" after I add and manipulate a
chart is the complete source data range of the current chart, so that's
why when adding a new chart then, I get this chart full of unwanted data.

Sadly, your tip does not solve my problem, since I want to do everything
in the background, i.e. I want to completely avoid that the current
selection or the current focus have any influence on the behaviour of my
VBA script. This is so that the user doesn't mess up the script with an
accidental click on some cell/sheet in the middle of processing - and I
do want to allow the user to maybe continue working on a different Excel
sheet. I'll just go with my workaround unless something better comes up.

Thank you!

Lars
Reply With Quote
  #4 (permalink)  
Old 07-24-2008, 12:04 PM
Andy Pope
 
Posts: n/a
Re: Add a new chart *without* default data?

Hi,

You did mention you where using code. Try this to create a blank chart
sheet.

Sub x()

Dim chtTemp As Chart

Set chtTemp = Sheet1.ChartObjects.Add(1, 1, 200, 200).Chart
chtTemp.Location Where:=xlLocationAsNewSheet

End Sub

Cheers
Andy

Lars Uffmann wrote:
> Hi Andy,
>
> Andy Pope wrote:
>
>> You could try making sure the active cell is not within your data set.

>
> Thank you, that did help me to understand where Excel is getting it's
> data from. And it works. The "active cell" after I add and manipulate a
> chart is the complete source data range of the current chart, so that's
> why when adding a new chart then, I get this chart full of unwanted data.
>
> Sadly, your tip does not solve my problem, since I want to do everything
> in the background, i.e. I want to completely avoid that the current
> selection or the current focus have any influence on the behaviour of my
> VBA script. This is so that the user doesn't mess up the script with an
> accidental click on some cell/sheet in the middle of processing - and I
> do want to allow the user to maybe continue working on a different Excel
> sheet. I'll just go with my workaround unless something better comes up.
>
> Thank you!
>
> Lars


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
Reply With Quote
  #5 (permalink)  
Old 07-24-2008, 01:30 PM
Lars Uffmann
 
Posts: n/a
Solution: Add a new chart *without* default data?

Hi Andy!

Andy Pope wrote:
> You did mention you where using code. Try this to create a blank chart
> sheet.
> Set chtTemp = Sheet1.ChartObjects.Add(1, 1, 200, 200).Chart
> chtTemp.Location Where:=xlLocationAsNewSheet



Thanks a lot! This is 95% of the solution I was looking for, and
probably the best Excel can do :)
Unfortunately, the Location method creates a copy of the chart object
and renders the old chart object returned by Add().Chart
obsolete/invalid. Also, the documentation does not say where the
"xlLocationAsNewSheet" inserts the chart. I *assume* it will always be
at Workbook.Charts(Workbook.Charts.Count + 1) and of course increase the
Charts Count. So I have to get a new handle to my chart by accessing
Workbook.Charts(Workbook.Charts.Count) after moving the chart.

What I did in the end was this:

Dim dummyWs As WorkSheet
Dim myChart As Chart

Set dummyWs = ActiveWorkbook.Worksheets.Add

dummyWs.ChartObjects.Add(1, 50, 100, 50).Chart.Location
xlLocationAsNewSheet, "my chart in a new sheet"
Set myChart = ActiveWorkbook.Charts(ActiveWorkbook.Charts.Count)

' do stuff with myChart

This gets the job done, so thank you very much!

Best Regards,

Lars
Reply With Quote
  #6 (permalink)  
Old 07-24-2008, 03:24 PM
Tushar Mehta (Microsoft MVP Excel 2000-2008)
 
Posts: n/a
Re: Solution: Add a new chart *without* default data?

My standard approach to losing the reference after changing the
location is

set chtTemp=chtTemp.Location(Where:=xlLocationAsNewShe et)

In your case, what I would do is just use the Charts.Add method. Also,
I have learnt not to trust Excel's decisions about what it puts in a
new chart. So, I always go through and delete any existing series.

Option Explicit

Sub doChart()
Dim aChart As Chart
Set aChart = Charts.Add()
With aChart.SeriesCollection
Do While .Count > 0: .Item(1).Delete: Loop
End With
End Sub



On Thu, 24 Jul 2008 15:30:25 +0200, Lars Uffmann <aral@nurfuerspam.de>
wrote:

>Hi Andy!
>
>Andy Pope wrote:
>> You did mention you where using code. Try this to create a blank chart
>> sheet.
>> Set chtTemp = Sheet1.ChartObjects.Add(1, 1, 200, 200).Chart
>> chtTemp.Location Where:=xlLocationAsNewSheet

>
>
>Thanks a lot! This is 95% of the solution I was looking for, and
>probably the best Excel can do :)
>Unfortunately, the Location method creates a copy of the chart object
>and renders the old chart object returned by Add().Chart
>obsolete/invalid. Also, the documentation does not say where the
>"xlLocationAsNewSheet" inserts the chart. I *assume* it will always be
>at Workbook.Charts(Workbook.Charts.Count + 1) and of course increase the
>Charts Count. So I have to get a new handle to my chart by accessing
>Workbook.Charts(Workbook.Charts.Count) after moving the chart.
>
>What I did in the end was this:
>
> Dim dummyWs As WorkSheet
> Dim myChart As Chart
>
> Set dummyWs = ActiveWorkbook.Worksheets.Add
>
> dummyWs.ChartObjects.Add(1, 50, 100, 50).Chart.Location
>xlLocationAsNewSheet, "my chart in a new sheet"
> Set myChart = ActiveWorkbook.Charts(ActiveWorkbook.Charts.Count)
>
> ' do stuff with myChart
>
>This gets the job done, so thank you very much!
>
>Best Regards,
>
> Lars

Reply With Quote
  #7 (permalink)  
Old 07-24-2008, 05:19 PM
Lars Uffmann
 
Posts: n/a
Re: Solution: Add a new chart *without* default data?

Tushar,

Tushar Mehta (Microsoft MVP Excel 2000-2008) wrote:
> My standard approach to losing the reference after changing the
> location is
> set chtTemp=chtTemp.Location(Where:=xlLocationAsNewShe et)


I might try again, but I tried this and I could swear that for the Chart
object, .Location did not return a new reference to a Chart object -
sadly.

> In your case, what I would do is just use the Charts.Add method. Also,
> I have learnt not to trust Excel's decisions about what it puts in a
> new chart. So, I always go through and delete any existing series.


You kinda missed the beginning of the discussion :) I decided to
explicitely *not* use the Charts.Add method because of what Excel puts
in that new chart. Andy's solution actually enables you to create a
*really* empty chart (without even a Series in it).

Thank you for your additions though!

Best Regards,

Lars
Reply With Quote
  #8 (permalink)  
Old 07-26-2008, 03:12 AM
Tushar Mehta (Microsoft MVP Excel 2000-2008)
 
Posts: n/a
Re: Solution: Add a new chart *without* default data?

Lars,

I've been using the Location method to get a reference to the new
object for several versions of Excel including 2007. Not to mention,
as is almost always the case, I tested the code before posting. {grin}

On Thu, 24 Jul 2008 19:19:43 +0200, Lars Uffmann <aral@nurfuerspam.de>
wrote:

>Tushar,
>
>Tushar Mehta (Microsoft MVP Excel 2000-2008) wrote:
>> My standard approach to losing the reference after changing the
>> location is
>> set chtTemp=chtTemp.Location(Where:=xlLocationAsNewShe et)

>
>I might try again, but I tried this and I could swear that for the Chart
> object, .Location did not return a new reference to a Chart object -
>sadly.
>
>> In your case, what I would do is just use the Charts.Add method. Also,
>> I have learnt not to trust Excel's decisions about what it puts in a
>> new chart. So, I always go through and delete any existing series.

>
>You kinda missed the beginning of the discussion :) I decided to
>explicitely *not* use the Charts.Add method because of what Excel puts
>in that new chart. Andy's solution actually enables you to create a
>*really* empty chart (without even a Series in it).
>
>Thank you for your additions though!
>
>Best Regards,
>
> Lars

Reply With Quote
  #9 (permalink)  
Old 07-28-2008, 08:27 AM
Lars Uffmann
 
Posts: n/a
Re: Solution: Add a new chart *without* default data?

Good morning Tushar,

Tushar Mehta (Microsoft MVP Excel 2000-2008) wrote:
> I've been using the Location method to get a reference to the new
> object for several versions of Excel including 2007. Not to mention,
> as is almost always the case, I tested the code before posting. {grin}


You were right. I have no idea what I was trying before that did not
work, but the Location object does indeed return the correct reference
to the new chart object, as you said. I can do without my previous
workaround now, thanks a lot! :)

Best Regards,

Lars
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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



All times are GMT. The time now is 06:03 AM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Anonymous Surfing | Loans | Loans | Teen Chat | Pay Day Loans



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109