For the case where you really need to swap two words in a string, depending on where the number is, the user-defined function (UDF) code is very simple:
Function OrderWords(sWord As String) As String
Dim aTemp As Variant
OrderWords = Trim(sWord)
aTemp = Split(sWord, " ")
If UBound(aTemp) = 1 Then
If IsNumeric(aTemp(1)) Then OrderWords = aTemp(1) & " " & aTemp(0)
End If
End Function
![Result 1](https://cdn.statically.io/img/i.sstatic.net/qFdFC.png)
If you want to get the date range for each of the rows, then the function will be a bit longer:
Function ParsePeriods(sWord As String) As Variant
Dim aTemp As Variant
Dim nYear As Integer
Dim sPeriod As String
Dim aRes(1 To 2) As Variant
ParsePeriods = OrderWords(sWord)
aTemp = Split(Trim(sWord), " ")
If UBound(aTemp) <> 1 Then Exit Function
If IsNumeric(aTemp(1)) Then
nYear = CInt(aTemp(1))
sPeriod = Left(Trim(aTemp(0)), 3)
Else
nYear = CInt(aTemp(0))
sPeriod = Left(Trim(aTemp(1)), 3)
End If
Select Case sPeriod
Case "Q1"
aRes(1) = DateSerial(nYear, 1, 1): aRes(2) = DateSerial(nYear, 3, 31)
Case "Q2"
aRes(1) = DateSerial(nYear, 4, 1): aRes(2) = DateSerial(nYear, 6, 30)
Case "Q3"
aRes(1) = DateSerial(nYear, 7, 1): aRes(2) = DateSerial(nYear, 9, 30)
Case "Q4"
aRes(1) = DateSerial(nYear, 10, 1): aRes(2) = DateSerial(nYear, 12, 31)
Case "Jan"
aRes(1) = DateSerial(nYear, 1, 1): aRes(2) = DateSerial(nYear, 1, 31)
Case "Feb"
aRes(1) = DateSerial(nYear, 2, 1): aRes(2) = Application.WorksheetFunction.EoMonth(aRes(1), 0)
Case "Mar"
aRes(1) = DateSerial(nYear, 3, 1): aRes(2) = DateSerial(nYear, 3, 31)
Case Else
aRes(1) = "Write the rest of": aRes(2) = "the options yourself"
End Select
ParsePeriods = aRes
End Function
Since the function returns two values, you need to enter it in two adjacent cells as an array formula, with pressing Ctrl+Shift+Enter
![Result 2](https://cdn.statically.io/img/i.sstatic.net/zNmA7.png)
The second option is preferable because with the first option you won't get the result shown in your screenshot - when sorting 2005 March will be lower than 2005 April because "A" is less than "M".
Q1 2022
->2022-01-01,2022-03-31
,Apr 2010
->2010-04-01,2010-04-30
etc.?