PDA

View Full Version : VBA function for Date


jakester
Dec 3, 2009, 12:55 PM
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

Perito
Dec 3, 2009, 01:43 PM
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