Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   VBA function for Date (https://www.askmehelpdesk.com/showthread.php?t=421797)

  • Dec 3, 2009, 12:55 PM
    jakester
    VBA function for Date
    Ok, here's my problem. I am trying to concatenate a Chart Title with a date in the MMM-YY format. I have to create a Chart in excel each month. If I create the chart in December, it would be for November's data.

    I can't figure out how to concatenate "Clinical Utilization: " & DateAdd("M",-1,Date)

    It would be nice if I could get the date format to be MMM-YY so that the Chart Title reads:

    Clinical Utilization: Nov-09

    Is this possible?


    Jake
  • Dec 3, 2009, 01:43 PM
    Perito

    I think you're confusing your "types". DateAdd returns a variant, and not a string.

    I suggest you do it this way.

    Dim tDate as date
    tDate = DateAdd("M", -1, Date) ' tDate is one month ago.

    Dim S As String
    S = "Clinical Utilization: " & Format(tDate, "MMM-YY")

    The value of S will be "Clinical Utilization: Nov-09"

    Of course, you don't need the "S" variable. Just shove into whatever cell you wish. But, you can use it, and then put it in the cell:

    Cells(1,1) = S

  • All times are GMT -7. The time now is 04:58 PM.