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
You could have a Workbook Sheeting Change Event handler that stores the sheet name, address, date/time and value in a log sheet. You could log every change, or just the most recent change for each sheet.
Last modified cell meaning the cell that was last changed within the work book (excluding any changes in the active worksheet, so basically visually the worksheet changes to the cell on another worksheet).
in principle that sounds like it would work, as it could sort through the worksheets and identify the most recent change (excluding the active worksheet) and then go to that next worksheet and cell.
I suspect that you are confusing what is meant by the Active Sheet. The Active Sheet is the sheet manually selected and the Active Cell is a cell in the Selected range on the Active Sheet.
You can make changes to a cell or range on any sheet using VBA but that won't necessarily be the Active Sheet or the Active Cell. You can, of course, make changes to more than one cell on any sheet. For example, if you clear a range or use an Array Formula.
You need to consider what you want to happen of someone (maybe you) selects a large range, or even the whole sheet, and presses Delete.
Bookmarks