im in stuck

Hứa Trần Hữu Trung 1 Reputation point
2021-04-02T10:31:04.943+00:00

Function GetDate()
Dim dateStr As Variant
Dim dateArr As Variant
Dim dateResult As Variant
Dim term As String
Dim termFormat As String
Dim regEx As New RegExp
Dim regEx2 As New RegExp
Dim dateFormat As String

Dim strPattern As String: strPattern = "{(.*?)}"
Dim nextCell As String
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
With regEx2
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With

'Set Myrange = ActiveSheet.Range("C1:C255")
'Set Myrange = ActiveSheet.Columns(1)
Dim regexDateStr As String
Dim a As String

'regexDateStr = Myrange.value
'Column 1 is B
For Each c In ActiveSheet.Range("B1:B255")
c.Activate
regexDateStr = c.value

If regEx.Test(regexDateStr) Then
'MsgBox (regexDateStr)

a = GetParen2(regexDateStr)
dateArr = Split(a, ".")
term = dateArr(0)
If ArrayLen(dateArr) > 0 Then
    dateStr = Date
    termFormat = dateArr(0)
    If ArrayLen(dateArr) > 1 Then
        termFormat = dateArr(1)
        Select Case (term)
            Case "TODAY"
            dateStr = Date
            Case "LASTDAY"
            dateStr = DateAdd("d", -1, Date)
            Case "LAST2DAY"
            dateStr = DateAdd("d", -2, Date)
        End Select

    End If

End If

If dateStr <> Empty Then
' dateResult = Format(dateStr, termFormat)
dateFormat = Format(dateStr, termFormat)
End If
'regEx2.Replace(
c.Offset(, 1).value = regEx2.Replace(regexDateStr, dateFormat)
End If

Next c

'MsgBox (dateResult)
'MsgBox (Format(cur, "dd/MM/yyyy"))
End Function

0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. BradyXDツ 186 Reputation points
    2022-03-25T20:06:57.317+00:00

    change case "LAST2DAY" to LASTDAY

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.