Compile Error in Code

P

Phil Hageman

In the following code, I receive a compile error: Sub or
Function not defined. In the fifth line, "ChartObjects" is
highlighted. Can someone help me clear this problem?

Sub GoToMetricsA1()
' GoToMetricsA1 Macro
Sheets("Metrics").Select
Range("A1").Select
ChartObjects("Chart13").activate
With ActiveChart.Parent
.Height = 250 ' use desired height in points
.Width = 350 ' use desired width in points
.Left = (Windows(ActiveWorkbook.Name).Width - _
.Width)/2
.Top = (Windows(ActiveWorkbook.Name).Height - _
.Height)/2
End With
End Sub
 
C

Chip Pearson

Phil,

Use

ActiveSheet.ChartObjects("Chart13").Activate


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
P

Phil Hageman

Thanks for your help Chip - appreciate your time.

I entered the change, per the following, and received Run-
time error '1004': "Unable to get the ChartObjects
property of the Worksheet class." The ActiveSheet... line
is highlighted yellow. Did I put this in wrong?

Thanks, Phil

Sub GoToMetricsA1()
' GoToMetricsA1 Macro
Sheets("Metrics").Select
Range("A1").Select
ActiveSheet.ChartObjects("Chart13").Active
With ActiveChart.Parent
.Height = 250 'use desired height in points
.Width = 350 'use desired width in poits
.Left = (Windows(ActiveWorkbook.Name).Width -
.Width) / 2
.Top = (Windows(ActiveWorkbook.Name).Height -
.Height) / 2
End With
End Sub
-----Original Message-----
Phil,

Use

ActiveSheet.ChartObjects("Chart13").Activate
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
..
 
C

Chip Pearson

Phil,

First off, the line
ActiveSheet.ChartObjects("Chart13").Active
should be
ActiveSheet.ChartObjects("Chart13").Activate

Second, are you sure you have a chart object named Chart13. You'll get the
error you got if no chart with that name exists. You might need a space
between 'Chart' and '13'.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
T

Tom Ogilvy

ActiveSheet.ChartObjects("Chart13").Active

should be

ActiveSheet.ChartObjects("Chart13").Activate

or

ActiveSheet.ChartObjects("Chart13").Select
 
P

Phil Hageman

Thanks, Chip - I misread the word, and indeed, there is a
space in the chart name. My mistakes. Thanks for
helping. Phil
 
P

Phil Hageman

Thanks for the help, Tom. Chip pointed to two mistakes I
made - carelessness on my part.

Could you answer a question: I need to manipulate the
screen position of the chart. As this code works, the
chart is positioning in the upper left corner.

Thanks, Phil
 
T

Tom Ogilvy

For me it was centered on the screen.

Is the chart smaller than the visible window?

Perhaps you need to check the values you are passing to top and left to see
what is calculated.
 
P

Phil Hageman

Yes, the chart is smaller than the screen. I made the
height 550 and width 650, so I sized it smaller than the
screen. The code has /2 at the end of the coding line.
I've tried changing them, but the chart remains in the
upper left corner.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top