Not used to using VBA. I have a program that logs 1 min snapshots of a data series and creates a log. Then I want to then take snapshots of the log X columns back to fill in other snapshot columns. Ie data 1 min ago, 10 min ago, 60 min ago, etc. Code seems to work fine as long as the log sheet is filled out enough. But if it's only been 8 min ago it has an error trying to copy 10 min ago data that doesn't exist. I can't seem to figure out why this Sub isn't working like i think.
Run-time error '1004' Application or object defined error. I thought my If statement would eliminate this.
Here's my code:
Sub tenMinBack()
Dim rng As Range
Application.CutCopyMode = False
Application.ScreenUpdating = False
ThisWorkbook.Worksheets("Log").Select
rng = Range(Cells(1, Columns.Count).End(xlToLeft).Offset(0,-10), Cells(13,Columns.Count).End(xlToLeft).Offset(0,-10)).Select
#### So I know this rng is pointing to cells that don't exist for first 10 minutes,
#### Not sure why this If statement isn't stopping it from attempting to copy it
If Not IsEmpty(rng) Then
rng.Copy
ThisWorkBook.Worksheets("Prices").Range("D3:D15").PasteSpecial xlValues
ThisWorkBook.Worksheets("Log").Cells.EntireColumn.AutoFit
ThisWorkBook.Worksheets("Prices").Cells.EntireColumn.AutoFit
End If
ThisWorkBook.Worksheets("Prices").Select
End Sub