Search code examples
vbaformattingcaption

insert month and year into a label caption


How do i change the format current month and year at the end of a caption. I have tried using a cell on the worksheet and then formatting it to mmmm yy however when i tell the caption to update on the user-form initialize sequence it comes through in a short date format. Below is the code as it stands.

 MobilePricing.Label313.Caption = "Daisy Group Vodafone Mobile Pricing Tool " & _
 Worksheets("Calculator").Range("V2")

Any advise on how i can change the format of the date to mmmm yy would be greatly appreciated.

Thanks


Solution

  • I am assuming V2 is holding a date value.

    MobilePricing.Label313.Caption = "Daisy Group Vodafone Mobile Pricing Tool " & _
     Format(Worksheets("Calculator").Range("V2"),"mmmm yy")
    

    I have used the Format function to convert the date into the format you want.