Skip to content

Instantly share code, notes, and snippets.

@iqfareez
Last active January 20, 2023 07:10
Show Gist options
  • Save iqfareez/c51dc9fa12f08fb678c7c441755cc0a3 to your computer and use it in GitHub Desktop.
Save iqfareez/c51dc9fa12f08fb678c7c441755cc0a3 to your computer and use it in GitHub Desktop.
Excel update day name on cell select

Excel Macro to dynamically update cell with day name

Demo

2023-01-19.16-06-00.mp4

You can download template file here.

Important

  1. Save your excel file with .xlsm (macro-enabled)
  2. Make sure the cell for date is formatted as Text (If formatted as Date, sometimes it would lead to incorrect day, perhaps due to locale). image
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
Dim currentYear As Integer
Dim selectedRow As Long
Dim selectedCol As Long
Dim validRange As Range
Dim dayAddress As String
Dim selectedDay As Integer
Dim monthValue As Integer
'Selecting outside of this range will be ignored
Set validRange = Range("B6:M36")
If Intersect(Target, validRange) Is Nothing Then
Exit Sub
End If
currentYear = Range("A4").Value
selectedRow = Target.Row 'Date row
selectedCol = Target.Column 'Month column
dayAddress = "A" & selectedRow
selectedDay = Range(dayAddress).Value
monthValue = selectedCol - 1
Range("O6").Value = selectedDay & "/" & monthValue & "/" & currentYear
Range("O5").Value = Format(Range("O6").Value, "dddd")
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment