PC Review


Reply
Thread Tools Rate Thread

code fails if graph is selected

 
 
Scott
Guest
Posts: n/a
 
      27th Mar 2008
This code fails if a graph on the same sheet is selected (clicking inside the
graph)

Columns("B:B").Select

If I unselect the graph (clicking ouside the graph) then code runs fine.

What can I put in the code to make sure the graphs are not selected?

 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      27th Mar 2008
When the graph is selected there is no activesheet so

if activesheet is nothing then
msgbox "Sorry... Please de-select the graph before continuing..."
else
columns("B").Select
--
HTH...

Jim Thomlinson


"Scott" wrote:

> This code fails if a graph on the same sheet is selected (clicking inside the
> graph)
>
> Columns("B:B").Select
>
> If I unselect the graph (clicking ouside the graph) then code runs fine.
>
> What can I put in the code to make sure the graphs are not selected?
>

 
Reply With Quote
 
Scott
Guest
Posts: n/a
 
      27th Mar 2008
So I guess this line which is before doesnt mean anything when the chart is
selected

Sheets("XYZ").Select

BTW the error message is

Run-time error "1004"
Method 'Columns' of object '_Global' failed

"Jim Thomlinson" wrote:

> When the graph is selected there is no activesheet so
>
> if activesheet is nothing then
> msgbox "Sorry... Please de-select the graph before continuing..."
> else
> columns("B").Select
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Scott" wrote:
>
> > This code fails if a graph on the same sheet is selected (clicking inside the
> > graph)
> >
> > Columns("B:B").Select
> >
> > If I unselect the graph (clicking ouside the graph) then code runs fine.
> >
> > What can I put in the code to make sure the graphs are not selected?
> >

 
Reply With Quote
 
Jim Thomlinson
Guest
Posts: n/a
 
      27th Mar 2008
Sorry... Not ActiveSheet. Should be ActiveCell.

Try this perhaps (I dont't tend to select things in my macros as you really
don't need to so this is just a guess)

Activesheet.Columns("B").select

Otherwise if you want to post your code we could probalby get rid of the
selects and get around this whole mess.
--
HTH...

Jim Thomlinson


"Scott" wrote:

> So I guess this line which is before doesnt mean anything when the chart is
> selected
>
> Sheets("XYZ").Select
>
> BTW the error message is
>
> Run-time error "1004"
> Method 'Columns' of object '_Global' failed
>
> "Jim Thomlinson" wrote:
>
> > When the graph is selected there is no activesheet so
> >
> > if activesheet is nothing then
> > msgbox "Sorry... Please de-select the graph before continuing..."
> > else
> > columns("B").Select
> > --
> > HTH...
> >
> > Jim Thomlinson
> >
> >
> > "Scott" wrote:
> >
> > > This code fails if a graph on the same sheet is selected (clicking inside the
> > > graph)
> > >
> > > Columns("B:B").Select
> > >
> > > If I unselect the graph (clicking ouside the graph) then code runs fine.
> > >
> > > What can I put in the code to make sure the graphs are not selected?
> > >

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      27th Mar 2008
Try this -

If Not ActiveChart Is Nothing Then
If TypeName(ActiveChart.Parent) <> "ChartObject" Then
Windows(2).Activate
End If
End If

Columns("B:B").Select

Tut tut though, shouldn't be select'ing anyway <g>

Regards,
Peter T


"Scott" <(E-Mail Removed)> wrote in message
news:23CFE9C2-9DCF-47A7-8F77-(E-Mail Removed)...
> This code fails if a graph on the same sheet is selected (clicking inside

the
> graph)
>
> Columns("B:B").Select
>
> If I unselect the graph (clicking ouside the graph) then code runs fine.
>
> What can I put in the code to make sure the graphs are not selected?
>



 
Reply With Quote
 
Andy Pope
Guest
Posts: n/a
 
      27th Mar 2008
Hi,

Range("B1").EntireColumn.select

Cheers
Andy

Scott wrote:
> This code fails if a graph on the same sheet is selected (clicking inside the
> graph)
>
> Columns("B:B").Select
>
> If I unselect the graph (clicking ouside the graph) then code runs fine.
>
> What can I put in the code to make sure the graphs are not selected?
>


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
 
Reply With Quote
 
Scott
Guest
Posts: n/a
 
      31st Mar 2008
Being new to VBA programming I thought you had to select the sheet and select
the cells before performing any operation on them. Your suggestion
"Activesheet.Columns("B").select" worked. Thanks. Guess I still have a lot
to learn about VBA.

"Jim Thomlinson" wrote:

> Sorry... Not ActiveSheet. Should be ActiveCell.
>
> Try this perhaps (I dont't tend to select things in my macros as you really
> don't need to so this is just a guess)
>
> Activesheet.Columns("B").select
>
> Otherwise if you want to post your code we could probalby get rid of the
> selects and get around this whole mess.
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Scott" wrote:
>
> > So I guess this line which is before doesnt mean anything when the chart is
> > selected
> >
> > Sheets("XYZ").Select
> >
> > BTW the error message is
> >
> > Run-time error "1004"
> > Method 'Columns' of object '_Global' failed
> >
> > "Jim Thomlinson" wrote:
> >
> > > When the graph is selected there is no activesheet so
> > >
> > > if activesheet is nothing then
> > > msgbox "Sorry... Please de-select the graph before continuing..."
> > > else
> > > columns("B").Select
> > > --
> > > HTH...
> > >
> > > Jim Thomlinson
> > >
> > >
> > > "Scott" wrote:
> > >
> > > > This code fails if a graph on the same sheet is selected (clicking inside the
> > > > graph)
> > > >
> > > > Columns("B:B").Select
> > > >
> > > > If I unselect the graph (clicking ouside the graph) then code runs fine.
> > > >
> > > > What can I put in the code to make sure the graphs are not selected?
> > > >

 
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
Graph not plotting correctly if source not selected Frank Microsoft Excel Programming 5 7th Jun 2010 05:49 PM
Code in Form to Change all Selected Records & Save Them Then Uncheck Selected Cory Microsoft Access VBA Modules 0 4th Dec 2007 04:18 PM
report with Graph Ole object, can I manipulate the datasource of the graph by code? Philip Leduc Microsoft Access Reports 1 27th Jun 2005 11:03 AM
report with Graph Ole object, can I manipulate the datasource of the graph by code? Philip Leduc Microsoft Access 0 23rd Jun 2005 12:34 AM
Graph - display selected data labels Mike Collard Microsoft Access VBA Modules 0 29th Mar 2004 04:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:01 PM.