Im trying to create a code that takes me to the last modified cell between all other worksheets (except the active worksheet). i have the below code but its not working.
any help to rectify would be much appreciated.
PHP Code:
Option Explicit
Sub GoToLastModifiedCell()
Dim ws As Worksheet
Dim lastModifiedCell As Range
'Loop through all worksheets except the active one
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> ActiveSheet.Name Then
'Check if the worksheet has a last modified cell
If ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious) Is Nothing Then
'If not, go to the next worksheet
GoTo NextSheet
End If
'If the worksheet has a last modified cell, check if it's the most recent
If lastModifiedCell Is Nothing Then
Set lastModifiedCell = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
ElseIf ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Modified > lastModifiedCell.Modified Then
Set lastModifiedCell = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
End If
End If
NextSheet:
Next ws
'Go to the last modified cell
lastModifiedCell.Active
End Sub
Bookmarks