Returns the text of quarter (3Q2024 or 1Q2017) with offset of the passed argument.
as in 4Q2023 or 2Q2019
Function CalculateQuarterText(Quarter1234QYYYY, QOffset)
' Returns the text of quarter with offset of the passed argument
' as in 4Q2023 or 2Q2019
'
Rett = "" ' Quarter1234QYYYY
CuQ = Val(Left(Quarter1234QYYYY, 1))
CuY = Val(Mid(Quarter1234QYYYY, 3))
If QOffset < -4 Or QOffset > 4 Then GoTo ByeBye
Rett = CuQ + QOffset & "Q" & CuY ' Assume it is withing same year
If CuQ + QOffset = 0 Then ' If going back prior to this year
Rett = "4Q" & CuY - 1
ElseIf CuQ + QOffset < 0 Then ' If going back prior to this year
Rett = 4 + (CuQ + QOffset) & "Q" & CuY - 1
ElseIf CuQ + QOffset > 4 Then
Rett = CuQ + QOffset - 4 & "Q" & CuY + 1
End If
ByeBye:
CalculateQuarterText = Rett
End Function
' Returns the text of quarter with offset of the passed argument
' as in 4Q2023 or 2Q2019
'
Rett = "" ' Quarter1234QYYYY
CuQ = Val(Left(Quarter1234QYYYY, 1))
CuY = Val(Mid(Quarter1234QYYYY, 3))
If QOffset < -4 Or QOffset > 4 Then GoTo ByeBye
Rett = CuQ + QOffset & "Q" & CuY ' Assume it is withing same year
If CuQ + QOffset = 0 Then ' If going back prior to this year
Rett = "4Q" & CuY - 1
ElseIf CuQ + QOffset < 0 Then ' If going back prior to this year
Rett = 4 + (CuQ + QOffset) & "Q" & CuY - 1
ElseIf CuQ + QOffset > 4 Then
Rett = CuQ + QOffset - 4 & "Q" & CuY + 1
End If
ByeBye:
CalculateQuarterText = Rett
End Function
Quarter1234QYYYY, QOffset
CalculateQuarterText("2Q2023", -3)
Views 70
Downloads 20
CodeID
DB ID