Run-Time error 1004 issues

rjplante

Well-known Member
Joined
Oct 31, 2008
Messages
574
Office Version
  1. 365
Platform
  1. 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


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
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
If your column is 2 you cannot offset -19 columns. You will be off the page so to speak.
 
Upvote 0
Thanks Steve for the fix. I just had the row and column values mixed up. Works great. Major Duh moment for me.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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