PC Review


Reply
Thread Tools Rate Thread

chart select causes error 1004

 
 
Scooter
Guest
Posts: n/a
 
      8th Dec 2008
The code at the bottom use to work in Excel 2003 but now in Excel 2007 I get
the error message when it executes the ActiveSheet line:

Run-time error '1004':
Application-defined or object-defined erro
---------------------------------------------------------------------------------------------
dim shtcnt as integer

For shtcnt = 2 To (ActiveWorkbook.Sheets.Count - 1)
ActiveWorkbook.Sheets(shtcnt).Select
ActiveSheet.ChartObjects("xyz chart").Selec
---------------------------------------------------------------------------------------------
I have verified that "xyz chart" exists by selecting the chart with Alt +
mouse click and seeing the name in the Name Box left of the Formula Bar. Any
ideas whats wrong?

 
Reply With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      8th Dec 2008
You probably don't have a chart with that name on every sheet you're testing.
Try something like this

Dim shtcnt As Long
Dim aWB As Workbook
Dim myWS As Worksheet
Dim ChtObj As ChartObject

Set aWB = ActiveWorkbook
For shtcnt = 2 To (aWB.Sheets.Count - 1)
Set myWS = aWB.Sheets(shtcnt)
For Each ChtObj In myWS.ChartObjects
If ChtObj.Name = "xyz chart" Then
ChtObj.Select
End If

Next ChtObj
Next shtcnt

--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"Scooter" wrote:

> The code at the bottom use to work in Excel 2003 but now in Excel 2007 I get
> the error message when it executes the ActiveSheet line:
>
> Run-time error '1004':
> Application-defined or object-defined error
> ---------------------------------------------------------------------------------------------
> dim shtcnt as integer
>
> For shtcnt = 2 To (ActiveWorkbook.Sheets.Count - 1)
> ActiveWorkbook.Sheets(shtcnt).Select
> ActiveSheet.ChartObjects("xyz chart").Select
> ---------------------------------------------------------------------------------------------
> I have verified that "xyz chart" exists by selecting the chart with Alt +
> mouse click and seeing the name in the Name Box left of the Formula Bar. Any
> ideas whats wrong?
>

 
Reply With Quote
 
Scooter
Guest
Posts: n/a
 
      8th Dec 2008
Since some of the charts are the same name in different worksheets this
probably wont work for me. I'm still puzzled why it use to work under 2003
but wont work under 2007.

"Barb Reinhardt" wrote:

> You probably don't have a chart with that name on every sheet you're testing.
> Try something like this
>
> Dim shtcnt As Long
> Dim aWB As Workbook
> Dim myWS As Worksheet
> Dim ChtObj As ChartObject
>
> Set aWB = ActiveWorkbook
> For shtcnt = 2 To (aWB.Sheets.Count - 1)
> Set myWS = aWB.Sheets(shtcnt)
> For Each ChtObj In myWS.ChartObjects
> If ChtObj.Name = "xyz chart" Then
> ChtObj.Select
> End If
>
> Next ChtObj
> Next shtcnt
>
> --
> HTH,
> Barb Reinhardt
>
> If this post was helpful to you, please click YES below.
>
>
>
> "Scooter" wrote:
>
> > The code at the bottom use to work in Excel 2003 but now in Excel 2007 I get
> > the error message when it executes the ActiveSheet line:
> >
> > Run-time error '1004':
> > Application-defined or object-defined error
> > ---------------------------------------------------------------------------------------------
> > dim shtcnt as integer
> >
> > For shtcnt = 2 To (ActiveWorkbook.Sheets.Count - 1)
> > ActiveWorkbook.Sheets(shtcnt).Select
> > ActiveSheet.ChartObjects("xyz chart").Select
> > ---------------------------------------------------------------------------------------------
> > I have verified that "xyz chart" exists by selecting the chart with Alt +
> > mouse click and seeing the name in the Name Box left of the Formula Bar. Any
> > ideas whats wrong?
> >

 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      8th Dec 2008
Have you tried it? It's looking for charts of name "xyz chart" on every
sheet between sheet count 2 and the next to last sheet.

"Scooter" wrote:

> Since some of the charts are the same name in different worksheets this
> probably wont work for me. I'm still puzzled why it use to work under 2003
> but wont work under 2007.
>
> "Barb Reinhardt" wrote:
>
> > You probably don't have a chart with that name on every sheet you're testing.
> > Try something like this
> >
> > Dim shtcnt As Long
> > Dim aWB As Workbook
> > Dim myWS As Worksheet
> > Dim ChtObj As ChartObject
> >
> > Set aWB = ActiveWorkbook
> > For shtcnt = 2 To (aWB.Sheets.Count - 1)
> > Set myWS = aWB.Sheets(shtcnt)
> > For Each ChtObj In myWS.ChartObjects
> > If ChtObj.Name = "xyz chart" Then
> > ChtObj.Select
> > End If
> >
> > Next ChtObj
> > Next shtcnt
> >
> > --
> > HTH,
> > Barb Reinhardt
> >
> > If this post was helpful to you, please click YES below.
> >
> >
> >
> > "Scooter" wrote:
> >
> > > The code at the bottom use to work in Excel 2003 but now in Excel 2007 I get
> > > the error message when it executes the ActiveSheet line:
> > >
> > > Run-time error '1004':
> > > Application-defined or object-defined error
> > > ---------------------------------------------------------------------------------------------
> > > dim shtcnt as integer
> > >
> > > For shtcnt = 2 To (ActiveWorkbook.Sheets.Count - 1)
> > > ActiveWorkbook.Sheets(shtcnt).Select
> > > ActiveSheet.ChartObjects("xyz chart").Select
> > > ---------------------------------------------------------------------------------------------
> > > I have verified that "xyz chart" exists by selecting the chart with Alt +
> > > mouse click and seeing the name in the Name Box left of the Formula Bar. Any
> > > ideas whats wrong?
> > >

 
Reply With Quote
 
Scooter
Guest
Posts: n/a
 
      8th Dec 2008
I had to delete "Next ChtObj" and change "Next shtcnt" to "Next" to get it to
compile.
The line "Set myWS = aWB.Sheets(shtcnt)" doesnt appear to have worked since
after that line executed I checked the workbook and that sheet was not
selected.

I get a run-time error '91': for the code that executes after what I had
posted.


"Barb Reinhardt" wrote:

> Have you tried it? It's looking for charts of name "xyz chart" on every
> sheet between sheet count 2 and the next to last sheet.
>
> "Scooter" wrote:
>
> > Since some of the charts are the same name in different worksheets this
> > probably wont work for me. I'm still puzzled why it use to work under 2003
> > but wont work under 2007.
> >
> > "Barb Reinhardt" wrote:
> >
> > > You probably don't have a chart with that name on every sheet you're testing.
> > > Try something like this
> > >
> > > Dim shtcnt As Long
> > > Dim aWB As Workbook
> > > Dim myWS As Worksheet
> > > Dim ChtObj As ChartObject
> > >
> > > Set aWB = ActiveWorkbook
> > > For shtcnt = 2 To (aWB.Sheets.Count - 1)
> > > Set myWS = aWB.Sheets(shtcnt)
> > > For Each ChtObj In myWS.ChartObjects
> > > If ChtObj.Name = "xyz chart" Then
> > > ChtObj.Select
> > > End If
> > >
> > > Next ChtObj
> > > Next shtcnt
> > >
> > > --
> > > HTH,
> > > Barb Reinhardt
> > >
> > > If this post was helpful to you, please click YES below.
> > >
> > >
> > >
> > > "Scooter" wrote:
> > >
> > > > The code at the bottom use to work in Excel 2003 but now in Excel 2007 I get
> > > > the error message when it executes the ActiveSheet line:
> > > >
> > > > Run-time error '1004':
> > > > Application-defined or object-defined error
> > > > ---------------------------------------------------------------------------------------------
> > > > dim shtcnt as integer
> > > >
> > > > For shtcnt = 2 To (ActiveWorkbook.Sheets.Count - 1)
> > > > ActiveWorkbook.Sheets(shtcnt).Select
> > > > ActiveSheet.ChartObjects("xyz chart").Select
> > > > ---------------------------------------------------------------------------------------------
> > > > I have verified that "xyz chart" exists by selecting the chart with Alt +
> > > > mouse click and seeing the name in the Name Box left of the Formula Bar. Any
> > > > ideas whats wrong?
> > > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Floating Bar Chart 1004 error Oz Viking Microsoft Excel Programming 0 10th Aug 2009 01:24 AM
Chart runtime error 1004 please help ryan.fitzpatrick3@safeway.com Microsoft Excel Programming 2 6th Oct 2007 03:11 PM
create chart error '1004' .. =?Utf-8?B?RGFuaWVs?= Microsoft Excel Programming 4 6th Oct 2005 01:23 AM
Error 1004 using array in Sheet select. =?Utf-8?B?VHJlZm9y?= Microsoft Excel Misc 4 7th Sep 2005 07:29 PM
Run-time 1004 error on range select Morgan Microsoft Excel Programming 3 11th Nov 2003 11:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:40 PM.