Home » excel » excel – Output date month in uppercase

excel – Output date month in uppercase

Posted by: admin May 14, 2020 Leave a comment

Questions:

So i have Rng.Offset(0, xOffsetColumn).Value = UCase(Date) followed by Rng.Offset(0, xOffsetColumn).NumberFormat = "MMMM" which outputs the current date and formats it to the current month name but Ucase() doesn’t capitalize the name, is it because Date is not a string? or because of the formatting .NumberFormat afterwords?

Here is part the code:

If Not rngColJ Is Nothing Then
    For Each Rng In rngColJ
        If Not VBA.IsEmpty(Rng.Value) Then
            Rng.Offset(0, xOffsetColumn).Value = UCase(Format(d, "MMMM"))
        Else
            Rng.Offset(0, xOffsetColumn).ClearContents
        End If
    Next
End If
How to&Answers:

You need to first make a string and the Ucase() it.

Consider:

Sub dural()
    Dim d As Date
    d = Now
    MsgBox UCase(Format(d, "MMM"))
End Sub

Answer:

Sub Which_Month()
Dim A As String

    A = UCase(Format(Date, "mmmm"))
    Debug.Print A
    Msgbox A

End Sub