Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Chart versus Work Sheet Code Failure

Hi All
I have a problem when I update a workbook where I have selected (using sheet
tab not in code) a Chart sheet as opposed to a Work sheet.

If I select a Worksheet and run a procedure that updates a number of other
Worksheets everything is fine. If I have a Chart Sheet selected, then I get
an error, even though the code makes no specfic reference to the Chart.
Examples of the code that throw an error follow (shPressure and ShControl
are both worksheets)

The first refers to a work sheet (not chart), but if a chart is selected I
get Run-time error 13 Type Mismatch, the second Run-time error 1004 Method
'Rows' of object '_global' failed.

shPressure.Rows("6:7").Copy Destination:=shPressure.Range("A" & xFirstRow)

xlrow = shControl.Cells(Rows.Count, "K").End(xlUp).Row


--
Cheers
Nigel




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Chart versus Work Sheet Code Failure

Hi All
I have added a fix that saves the current sheet name (worksheet or chart
sheet) before the procedure runs, set the current sheet to the one being
updated and then restores the current sheet at the end. That works. But I
am still curious as to why having a chart selected changes the way code
references work in other, unrelated sheets?

--
Cheers
Nigel



"Nigel" wrote in message
...
Hi All
I have a problem when I update a workbook where I have selected (using

sheet
tab not in code) a Chart sheet as opposed to a Work sheet.

If I select a Worksheet and run a procedure that updates a number of other
Worksheets everything is fine. If I have a Chart Sheet selected, then I

get
an error, even though the code makes no specfic reference to the Chart.
Examples of the code that throw an error follow (shPressure and ShControl
are both worksheets)

The first refers to a work sheet (not chart), but if a chart is selected I
get Run-time error 13 Type Mismatch, the second Run-time error 1004 Method
'Rows' of object '_global' failed.

shPressure.Rows("6:7").Copy Destination:=shPressure.Range("A" & xFirstRow)

xlrow = shControl.Cells(Rows.Count, "K").End(xlUp).Row


--
Cheers
Nigel






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Chart versus Work Sheet Code Failure

I got the code to run simply by adding

shPressure.select

at the start of the procedure.

So now it goes something like this...

Dim ActiveObject As Variant
Set ActiveObject = ActiveSheet
shPressure.Select
VBAProject.shPressure.Rows("6:7").Copy Destination:=shPressure.Range("A1")
xlrow = shControl.Cells(Rows.Count, "K").End(xlUp).Row
ActiveObject.Select

The ActiveObject stores the sheet that was originally selected prior to
running the code. It is a little ugly but it works. Why it won't work to
begin with is beyond me...

HTH

"Nigel" wrote:

Hi All
I have a problem when I update a workbook where I have selected (using sheet
tab not in code) a Chart sheet as opposed to a Work sheet.

If I select a Worksheet and run a procedure that updates a number of other
Worksheets everything is fine. If I have a Chart Sheet selected, then I get
an error, even though the code makes no specfic reference to the Chart.
Examples of the code that throw an error follow (shPressure and ShControl
are both worksheets)

The first refers to a work sheet (not chart), but if a chart is selected I
get Run-time error 13 Type Mismatch, the second Run-time error 1004 Method
'Rows' of object '_global' failed.

shPressure.Rows("6:7").Copy Destination:=shPressure.Range("A" & xFirstRow)

xlrow = shControl.Cells(Rows.Count, "K").End(xlUp).Row


--
Cheers
Nigel





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
Check Activesheet for chart sheet or work sheet NSK Charts and Charting in Excel 1 July 17th 07 09:00 PM
vb code for renaming a work sheet with a cell reference John Britto Excel Discussion (Misc queries) 3 September 17th 06 07:12 PM
Memory failure : Getting Sum to work Drew Cutter New Users to Excel 5 April 25th 06 07:35 PM
R1C1 versus A1 in VB code Bill Sturdevant[_2_] Excel Programming 8 January 27th 05 03:03 PM
VB Code does not work when sheet or workbook is protected novicevbaer[_5_] Excel Programming 1 August 25th 04 11:34 PM


All times are GMT +1. The time now is 09:04 AM.

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"