This function is just meant to run through a whole bunch of sheets and clear out old data and copy it to a historical range in preparation for actual data analysis and transfer. When I attempt to reset the range objects in order to continue the execution of the clearing of cells in the sheet I get a "Run-time error '424': Object required.
I am particularly perplexed by this error because it works for the two objects before it without a problem. Spelling appears to be proper. Any ideas? Error is occurring in the Else statement at the bottom of the function on the line Set historStartRangePuts = historStartRangePuts.Offset(0,10)
Sub ClearTransferHistoricalOI(oiSheet As Worksheet)
Dim continue As Boolean
Dim startRangePuts As Range, startRangeCalls As Range, historStartRangePuts As Range, historStartRangeCalls As Range
Dim newStartRangePuts As Range, newstartRangeCalls As Range, newHistorStartRangePuts As Range, newHistorStartRangeCalls As Range
Dim columnCounter As Integer
'Sets start range
Set startRangePuts = oiSheet.Cells(5, 1)
Set startRangeCalls = oiSheet.Cells(5, 3)
Set historStartRangePuts = oiSheet.Cells(5, 6)
Set historStartRangeCalls = oiSheet.Cells(5, 8)
continue = True
oiSheet.Activate
'Attempts to catch already cleared sheets
If IsEmpty(startRangePuts) = True Then
continue = False
End If
Do While continue = True
'Clears puts and calls historical data
oiSheet.Range(historStartRangePuts, historStartRangePuts.Offset(0, 1)).Select
oiSheet.Range(Selection, Selection.End(xlDown)).ClearContents
oiSheet.Range(historStartRangeCalls, historStartRangeCalls.Offset(0, 1)).Select
oiSheet.Range(Selection, Selection.End(xlDown)).ClearContents
'Transfers puts and calls current data to historical data cols
'Puts
oiSheet.Range(startRangePuts, startRangePuts.Offset(0, 1)).Select
oiSheet.Range(Selection, Selection.End(xlDown)).Cut historStartRangePuts
'Calls
oiSheet.Range(startRangeCalls, startRangeCalls.Offset(0, 1)).Select
oiSheet.Range(Selection, Selection.End(xlDown)).Cut historStartRangeCalls
If IsEmpty(startRangePuts.Offset(0, 10)) = True Then
continue = False
Else
Set startRangeCalls = startRangeCalls.Offset(0, 10)
Set startRangePuts = startRangePuts.Offset(0, 10)
Set historStartRangePuts = startRangePuts.Offset(0, 5)
Set historStartRangeCalls = startRangeCalls.Offset(0, 5)
End If
Loop
End Sub