Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Loop through sheets, deselect charts

My workbook has approximately 100 worksheets, and about 30
of these have charts. I would like to loop through the
sheets, and make sure that cell A1 is selected.

Sub SelectA1
For i = 1 to Sheets.count
Sheets(i).visible = True
Sheets(i).select
cells(1,1).select
Next i
End Sub

The problem is, sometimes a chart is selected, and so I
get an error if I try to select cell A1.

Can anyone improve my loop to handle the cases when a
chart is selected?

Thanks in advance
Daniel Bonallack
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Loop through sheets, deselect charts

Daniel,

Change
cells(1,1).select
to
Range("A1").Select
Even though both work for me in Excel97

Another approach is to select the cell under the chart first

On Error Resume Next
Range(ActiveChart.Parent.TopLeftCell.Address).Sele ct
on Error goto 0
Range("A1").Select

--
sb
"Daniel Bonallack" wrote in message
...
My workbook has approximately 100 worksheets, and about 30
of these have charts. I would like to loop through the
sheets, and make sure that cell A1 is selected.

Sub SelectA1
For i = 1 to Sheets.count
Sheets(i).visible = True
Sheets(i).select
cells(1,1).select
Next i
End Sub

The problem is, sometimes a chart is selected, and so I
get an error if I try to select cell A1.

Can anyone improve my loop to handle the cases when a
chart is selected?

Thanks in advance
Daniel Bonallack



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default Loop through sheets, deselect charts

Hi Steve -

Cells(1, 1).Select
only worked in Excel 97 if the chart object was selected (by holding
Shift and selecting the chart). If the chart or a chart element was
selected, I got an error.

Range("A1").Select
worked in both cases.

I don't know why one works and the other fails.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
http://www.geocities.com/jonpeltier/Excel/index.html
_______

steve wrote:

Daniel,

Change
cells(1,1).select
to
Range("A1").Select
Even though both work for me in Excel97

Another approach is to select the cell under the chart first

On Error Resume Next
Range(ActiveChart.Parent.TopLeftCell.Address).Sele ct
on Error goto 0
Range("A1").Select

--
sb
"Daniel Bonallack" wrote in message
...

My workbook has approximately 100 worksheets, and about 30
of these have charts. I would like to loop through the
sheets, and make sure that cell A1 is selected.

Sub SelectA1
For i = 1 to Sheets.count
Sheets(i).visible = True
Sheets(i).select
cells(1,1).select
Next i
End Sub

The problem is, sometimes a chart is selected, and so I
get an error if I try to select cell A1.

Can anyone improve my loop to handle the cases when a
chart is selected?

Thanks in advance
Daniel Bonallack





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Loop through sheets, deselect charts

Thanks Steve/Jon - such a simple solution


-----Original Message-----
Hi Steve -

Cells(1, 1).Select
only worked in Excel 97 if the chart object was

selected (by holding
Shift and selecting the chart). If the chart or a chart

element was
selected, I got an error.

Range("A1").Select
worked in both cases.

I don't know why one works and the other fails.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
http://www.geocities.com/jonpeltier/Excel/index.html
_______

steve wrote:

Daniel,

Change
cells(1,1).select
to
Range("A1").Select
Even though both work for me in Excel97

Another approach is to select the cell under the chart

first

On Error Resume Next
Range(ActiveChart.Parent.TopLeftCell.Address).Sele ct
on Error goto 0
Range("A1").Select

--
sb
"Daniel Bonallack" wrote in

message
...

My workbook has approximately 100 worksheets, and about

30
of these have charts. I would like to loop through the
sheets, and make sure that cell A1 is selected.

Sub SelectA1
For i = 1 to Sheets.count
Sheets(i).visible = True
Sheets(i).select
cells(1,1).select
Next i
End Sub

The problem is, sometimes a chart is selected, and so I
get an error if I try to select cell A1.

Can anyone improve my loop to handle the cases when a
chart is selected?

Thanks in advance
Daniel Bonallack





.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Loop through sheets, deselect charts

Jon,

Don't know why, either. But ran across this problem in some of my code
and resorted to Range instead of Cells when going from a chart to the
worksheet.

The Help didn't make it clear...

--
sb
"Jon Peltier" wrote in message
...
Hi Steve -

Cells(1, 1).Select
only worked in Excel 97 if the chart object was selected (by holding
Shift and selecting the chart). If the chart or a chart element was
selected, I got an error.

Range("A1").Select
worked in both cases.

I don't know why one works and the other fails.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
http://www.geocities.com/jonpeltier/Excel/index.html
_______

steve wrote:

Daniel,

Change
cells(1,1).select
to
Range("A1").Select
Even though both work for me in Excel97

Another approach is to select the cell under the chart first

On Error Resume Next
Range(ActiveChart.Parent.TopLeftCell.Address).Sele ct
on Error goto 0
Range("A1").Select

--
sb
"Daniel Bonallack" wrote in message
...

My workbook has approximately 100 worksheets, and about 30
of these have charts. I would like to loop through the
sheets, and make sure that cell A1 is selected.

Sub SelectA1
For i = 1 to Sheets.count
Sheets(i).visible = True
Sheets(i).select
cells(1,1).select
Next i
End Sub

The problem is, sometimes a chart is selected, and so I
get an error if I try to select cell A1.

Can anyone improve my loop to handle the cases when a
chart is selected?

Thanks in advance
Daniel Bonallack







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
Loop all Sheets not working. Pank New Users to Excel 12 February 27th 07 11:55 AM
Loop through varible list of sheets [email protected] Excel Discussion (Misc queries) 2 January 5th 07 08:45 AM
Use a loop to create multiple Charts - Suggestions ? APOEL Charts and Charting in Excel 1 July 29th 06 03:36 AM
Charts from Spread sheets nick g Excel Discussion (Misc queries) 3 July 27th 05 05:01 PM
ActiveChart.Deselect won't Deselect Mark Stephens Charts and Charting in Excel 2 June 16th 05 02:54 AM


All times are GMT +1. The time now is 07:25 AM.

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

About Us

"It's about Microsoft Excel"