Subscript out of Range Error

BuffaloGuy

New Member
Joined
Dec 5, 2017
Messages
28
My code was working perfectly, then I messed with it (only a little!). I was originally copying cells C3:G3, and copying them to the new worksheet. I extended it to include a few more cells that are running an exponetial moving average calculation, and the code runs for 5 or 6 lines before I get the Subscript out of range error. Thoughts?

VBA Code:
Option Explicit

Dim TimeToRun

Sub MacroRun()

    TimeToRun = Now + TimeValue("00:01:00")
    Application.OnTime TimeToRun, "Macro1"
    
    
End Sub

Sub Macro1()
    Calculate
    
    Worksheets("Calculation").Range("C3:M3").Copy
    
    Worksheets("Data").Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    
    Application.CutCopyMode = False

MacroRun

End Sub


Sub stopMacros()

    On Error Resume Next
    Application.OnTime TimeToRun, "Macro1", , False
    
End Sub

1611763279512.png



1611763058277.png
 

Attachments

  • 1611763223614.png
    1611763223614.png
    28.7 KB · Views: 5

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
That error means that the active workbook doesn't have a sheet called Calculations.
 
Upvote 0
The only reason I can see for that error would be that you have activated a different workbook, and that one doesn't have a Calculations sheet in it. If you mean the sheet in the same workbook as the code, you should refer to it as Thisworkbook.Worksheets("Calculations")
 
Upvote 0
If I have multiple workbooks open at the same time, because I want this code running in the background collecting data, could the code be attempting to find a tab called "Calculation" in the active workbook I am working on and not the one I want it running in?
 
Upvote 0
Yes, that's what I'm saying. If you use Thisworkbook.Sheets("Calculations") it will always refer to a sheet in the workbook with the code, regardless of which workbook is active.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,741
Messages
6,126,588
Members
449,319
Latest member
iaincmac

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top