Question : Automatically rename an Excel worksheet with previous days date, excluding weekends

I need to automatically rename an Excel worksheet with the previous days date but exclude weekend dates.  For example a new worksheet would be renamed 15 Dec if the current date was the 16 December.

However, if todays date is Monday 14 December, the worksheet would be renamed 11 Dec.

I hope this makes sense :)

Any help would be greatly appreciated.

Thanks.

Answer : Automatically rename an Excel worksheet with previous days date, excluding weekends

Sub RenameWorkSheet()
    Dim ShObj As Worksheet
   
    Set ShObj = ThisWorkbook.Worksheets(1)
   
    If UCase(WeekdayName(Weekday(DateAdd("d", -1, Now)))) = "SUNDAY" Then
        ShObj.Name = Format(DateAdd("d", -3, Now), "dd Mmm")
    Else
        ShObj.Name = Format(DateAdd("d", -1, Now), "dd Mmm")
    End If
End Sub
Random Solutions  
 
programming4us programming4us