Skip to content

Instantly share code, notes, and snippets.

@elyse0
Created June 13, 2022 18:23
Show Gist options
  • Save elyse0/c5a570f8405dae363246d224f275c70d to your computer and use it in GitHub Desktop.
Save elyse0/c5a570f8405dae363246d224f275c70d to your computer and use it in GitHub Desktop.
Function IsDate(cellValue) As Boolean
If Len(cellValue) > 9 Then
IsDate = True
Else
IsDate = False
End If
End Function
Sub SetDates()
Dim SelectedRange As Range
Set SelectedRange = Selection
RowCount = SelectedRange.Rows.Count
FirstRowIndex = CInt(Split(SelectedRange.Cells(1).Address, "$")(2))
LastRowIndex = FirstRowIndex + (RowCount - 1)
Dim GroupDate As String
For i = FirstRowIndex To LastRowIndex Step 1
Dim CellValueColumnA As String
Dim CellValueColumnB As String
CellValueColumnA = Cells(i, "A").Text
CellValueColumnB = Cells(i, "B").Text
If IsDate(CellValueColumnA) And CellValueColumnA = CellValueColumnB Then
GroupDate = Cells(i, "A").Text
MsgBox GroupDate
Else
MsgBox GroupDate
Cells(i, "A").NumberFormat = "@"
Cells(i, "A").Value = GroupDate
End If
Next i
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment