Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 1,073
Default On Error GoTo Label in a loop only working once.

Yesterday duncanslam (Steve Duncan) posted in Excel.misc for a way to
hide charts that don't have data. Seemed doable to me, so I had a go
only to discover the nasty problems associated with returning the
address of a chart's data.
Andy Pope cleared most of that up for me, thanks again Andy, so I then
had a go and thought I figured out a way of hiding dataless embedded
charts...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cht As ChartObject
Dim strSeries As String
For Each Cht In ActiveSheet.ChartObjects
On Error GoTo BLANK_CHART
strSeries = Cht.Chart.SeriesCollection(1).Formula
Cht.Visible = True
GoTo ALL_CHARTS
BLANK_CHART: Cht.Visible = False
ALL_CHARTS: Next Cht
End Sub

I had three XY scatter charts on the sheet, all with their own separate
X and Y values, and when I deleted the data (either X, Y or both), the
affected chart became invisible.

Unfortunately, when I delete the data of a second chart it results in
the Run-time error 1004 Unable to get the Formula Property of the
Series Class.

If I click End on the error message dialog the second (dataless) chart
is invisible, so at least the code worked.

So it seems to me like the On Error GoTo BLANK_CHART line somehow fails
for the second dataless chart.

Is there anyway around this problem?


Ken Johnson

  #2   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 2,489
Default On Error GoTo Label in a loop only working once.

Hi,

Try this revision to your code.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cht As ChartObject
Dim strSeries As String
Dim blnSeeChart As Boolean

On Error GoTo BLANK_CHART
For Each Cht In ActiveSheet.ChartObjects
blnSeeChart = True
strSeries = Cht.Chart.SeriesCollection(1).Formula
Cht.Visible = blnSeeChart
Next Cht

Exit Sub

BLANK_CHART:
blnSeeChart = False
Resume Next

End Sub

Cheers
Andy

Ken Johnson wrote:
Yesterday duncanslam (Steve Duncan) posted in Excel.misc for a way to
hide charts that don't have data. Seemed doable to me, so I had a go
only to discover the nasty problems associated with returning the
address of a chart's data.
Andy Pope cleared most of that up for me, thanks again Andy, so I then
had a go and thought I figured out a way of hiding dataless embedded
charts...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cht As ChartObject
Dim strSeries As String
For Each Cht In ActiveSheet.ChartObjects
On Error GoTo BLANK_CHART
strSeries = Cht.Chart.SeriesCollection(1).Formula
Cht.Visible = True
GoTo ALL_CHARTS
BLANK_CHART: Cht.Visible = False
ALL_CHARTS: Next Cht
End Sub

I had three XY scatter charts on the sheet, all with their own separate
X and Y values, and when I deleted the data (either X, Y or both), the
affected chart became invisible.

Unfortunately, when I delete the data of a second chart it results in
the Run-time error 1004 Unable to get the Formula Property of the
Series Class.

If I click End on the error message dialog the second (dataless) chart
is invisible, so at least the code worked.

So it seems to me like the On Error GoTo BLANK_CHART line somehow fails
for the second dataless chart.

Is there anyway around this problem?


Ken Johnson


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #3   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 1,073
Default On Error GoTo Label in a loop only working once.

Hi Andy,

that is absolutely fantastic!

Correct me if I'm wrong (I usual am)...

It looks to me like the solution involves removing the treatment of the
error from the inside of the loop. I wasn't aware of the need for
Resume Next, I had hoped that On Error GoTo could be repeatedly used
inside the loop.

Anyway, I still a bit confused, but excited that it now works.

Thanks again Andy.

Ken Johnson

  #4   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 2,489
Default On Error GoTo Label in a loop only working once.

Hi Ken,

The 'On Error Statement' help explains, much better than I could, why I
had to re-jig the error handling.

Cheers
Andy

Ken Johnson wrote:
Hi Andy,

that is absolutely fantastic!

Correct me if I'm wrong (I usual am)...

It looks to me like the solution involves removing the treatment of the
error from the inside of the loop. I wasn't aware of the need for
Resume Next, I had hoped that On Error GoTo could be repeatedly used
inside the loop.

Anyway, I still a bit confused, but excited that it now works.

Thanks again Andy.

Ken Johnson


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #5   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 1,073
Default On Error GoTo Label in a loop only working once.


Thanks Andy, I'll have a look.

Ken Johnson

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
Working spreadsheet highlighting function for Excel 2007 Mr. Low Excel Worksheet Functions 4 June 16th 06 06:12 PM
click & drag not working Teresa Excel Discussion (Misc queries) 2 February 25th 06 01:52 AM
amount of working days per month Nigel Excel Discussion (Misc queries) 2 November 29th 05 10:41 AM
Calculation with Working day of the year Box666 Excel Discussion (Misc queries) 4 November 10th 05 06:33 PM
label problem Raven Maniac Excel Worksheet Functions 5 November 10th 04 10:10 PM


All times are GMT +1. The time now is 12:41 PM.

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

About Us

"It's about Microsoft Excel"