tests all of col t sheet1 and sheet2 for max and renames sheet1 and sheet2 only if they both exist
Sub testd()
'tests all of col t sheet1 and sheet2 for max and renames sheet1 and sheet2 only if they both exist
Dim ws1 As Worksheet
Dim ws2 As Worksheet
On Error Resume Next
Set ws2 = Sheets("sheet2")
Set ws1 = Sheets("sheet1")
If Err.Number <> 0 Then
MsgBox "sheet1 or sheet2 do not exist exiting macro"
Exit Sub
End If
Set myrange1 = Worksheets("Sheet1").Range("t:t") 'change here if you just want to check 1 cell code could be a lot shorter if it is one cell only tho
Set myrange2 = Worksheets("Sheet2").Range("t:t") 'and here eg Range("t1") or range("t2:t1000")
firstws = WorksheetFunction.Max(myrange1)
secondws = WorksheetFunction.Max(myrange2)
If firstws = secondws Then
MsgBox ("max date is same on both ws. Exiting macro")
Exit Sub
End If
If firstws > secondws Then
Sheets("Sheet1").Name = "data"
Sheets("Sheet2").Name = "old data"
End If
If firstws < secondws Then
Sheets("Sheet1").Name = "old data"
Sheets("Sheet2").Name = "data"
End If
End Sub
Bookmarks