Share via

Method 'Range' of object'_Worksheet' failed

Anonymous
2014-07-29T12:26:34+00:00

Hi,

I have an Excel workbook with a couple of tabs.  What I want is that any time any cell is edited in the workbook, the cell "F2" in the tab "Safety Calculation" updates to today's date.

This is the code I've created:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

Worksheets("Safety Calculation").Range("F2") = Date

End Sub

I keep getting the Method 'Range' of object'_Worksheet' failed error.  What's wrong with my code?

Thanks,

GSalvat

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2014-07-29T12:45:28+00:00

Hi,

Try this:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

    On Error GoTo ExitPoint

Application.EnableEvents = False

    Worksheets("Safety Calculation").Range("F2") = Date

ExitPoint:

Application.EnableEvents = True

End Sub

You need to disable the Events, otherwise the act of placing the date in F2 re-triggers the event infinitely.  Use the error handling so that events are always left enabled.

Cheers

Rich

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2014-07-29T15:30:43+00:00

    Seems to be working, thanks!

    You're welcome.  Please mark my previous post as the answer.

    Cheers

    Rich

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-07-29T14:21:52+00:00

    Seems to be working, thanks!

    Was this answer helpful?

    0 comments No comments