Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Macro Error when I leave sheet

I have a macro that is set-up on a timer to repeat every 15 secs. When I
click on a different sheet in the workbook I get:
Run-time error '1004' Select method of range class failed.
Is there a way that I can still work in other worksheets as this macro is
running?
Thanks,
Sub MarketDelta1()
'''''''''''''''''

Worksheets("Futures").Range("O2:AA2").Select
Selection.Copy
Worksheets("Futures").Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
Worksheets("Futures").Range("O2").Select
'''''''''''''''''
' Call StartTimer to schedule the procedure again
If Time TimeSerial(16, 0, 0) Then
'do nothing
Else
StartTimer
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Macro Error when I leave sheet

Andy,

The problem is with the line

Worksheets("Futures").Range("O2:AA2").Select

You can't Select a range on a worksheet that is not already active -- you
can only Select on the ActiveSheet. Use two Selects:

Worksheets("Futures").Select
Range("O2:AA2").Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"andy" wrote in message
...
I have a macro that is set-up on a timer to repeat every 15 secs. When I
click on a different sheet in the workbook I get:
Run-time error '1004' Select method of range class failed.
Is there a way that I can still work in other worksheets as this macro is
running?
Thanks,
Sub MarketDelta1()
'''''''''''''''''

Worksheets("Futures").Range("O2:AA2").Select
Selection.Copy
Worksheets("Futures").Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
Worksheets("Futures").Range("O2").Select
'''''''''''''''''
' Call StartTimer to schedule the procedure again
If Time TimeSerial(16, 0, 0) Then
'do nothing
Else
StartTimer
End If
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Macro Error when I leave sheet

you can try this. you can select on any sheet but the active sheet. but you
don't need to select to copy and paste

Sub MarketDelta1()
'''''''''''''''''
Worksheets("Futures").Range("O2:AA2").Copy
Worksheets("Futures").Range("A2").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
' Worksheets("Futures").Range("O2").Select
'''''''''''''''''
' Call StartTimer to schedule the procedure again
If Time TimeSerial(16, 0, 0) Then
'do nothing
Else
StartTimer
End If
End Sub

--


Gary


"andy" wrote in message
...
I have a macro that is set-up on a timer to repeat every 15 secs. When I
click on a different sheet in the workbook I get:
Run-time error '1004' Select method of range class failed.
Is there a way that I can still work in other worksheets as this macro is
running?
Thanks,
Sub MarketDelta1()
'''''''''''''''''

Worksheets("Futures").Range("O2:AA2").Select
Selection.Copy
Worksheets("Futures").Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
Worksheets("Futures").Range("O2").Select
'''''''''''''''''
' Call StartTimer to schedule the procedure again
If Time TimeSerial(16, 0, 0) Then
'do nothing
Else
StartTimer
End If
End Sub



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
an error in a formula in annual leave Tia[_3_] Excel Worksheet Functions 1 August 19th 08 11:53 AM
Leave a cell COMPLETELY blank if there is an error hello Excel Discussion (Misc queries) 6 November 20th 07 01:48 PM
Leave Cell Blank if value is an error, below 0 or above 80 SteveC Excel Discussion (Misc queries) 4 May 12th 06 02:24 PM
leave sheet event Aaron Excel Programming 1 March 22nd 06 06:28 PM
Start a sheet event when i leave a sheet hans[_3_] Excel Programming 2 May 21st 04 09:43 PM


All times are GMT +1. The time now is 06:14 PM.

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"