rjplante
Well-known Member
- Joined
- Oct 31, 2008
- Messages
- 574
- Office Version
- 365
- Platform
- Windows
I have two small 5c x 20r tables separated by a single column. When my macro gets to the last row (numbered 20 in column 2 and column 8) I would like it to go the top row of the next/previous table. The code is listed below. It works just fine on all of the rows except when it gets to the last row in either table it fails on the "ActiveCell.Offset(6, -19).Select" lines in the code with the error: Run-Time error 1004: Application-defined or object-defined error. I don't know why it is failing on these rows. I have column 2 and 8 unlocked and all the others cells are locked to prevent editing. I use the vba to unprotect/protect the sheet so the cell status should not be a problem. What is causing these lines to fail with the same error?
Running Excel 2016.
Any insights are appreciated.
Thanks,
Robert
Running Excel 2016.
Any insights are appreciated.
Thanks,
Robert
Code:
Sub Endtime()
ActiveSheet.Unprotect Password:="123"
ActiveCell.Offset(0, 2).Select
ActiveCell.Value = Time
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = (ActiveCell.Offset(0, -1).Value - ActiveCell.Offset(0, -2).Value) * 86400
ActiveCell.Offset(0, -3).Select
Selection.Interior.Color = 5296274
If ActiveCell.Column = 2 And ActiveCell.Offset(0, -1).Value = "20" Then
ActiveCell.Offset(6, -19).Select
ElseIf ActiveCell.Column = 8 And ActiveCell.Offset(0, -1).Value = "20" Then
ActiveCell.Offset(-6, -19).Select
Else
ActiveCell.Offset(1, 0).Select
End If
ActiveSheet.Protect Password:="123"
End Sub