Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Check Activesheet for chart sheet or work sheet | Charts and Charting in Excel | |||
vb code for renaming a work sheet with a cell reference | Excel Discussion (Misc queries) | |||
Memory failure : Getting Sum to work | New Users to Excel | |||
R1C1 versus A1 in VB code | Excel Programming | |||
VB Code does not work when sheet or workbook is protected | Excel Programming |