Converting Dates

W

wutzke

Given a cell value of "Feb '08 " that is text, how could I
programically convert the value to 02/01/2008 in Date values
 
G

Gary''s Student

Sub qwerty()
s = "Feb '08 "
s = Application.WorksheetFunction.Substitute(s, "'", "20")
MsgBox (DateValue(s))
End Sub
 
L

Leith Ross

Given a cell value of "Feb '08 " that is text, how could I
programically convert the value to 02/01/2008 in Date values

Hello wutzke,

Here is one way. The single quote is represented by Chr$(39) for
readability.

Dim D

D = Split("Feb '08", Chr$(39))
D = CDate(D(0) & "1, " & D(1)) 'D is now = 2/01/2008

Sincerely,
Leith Ross
 
R

Rick Rothstein \(MVP - VB\)

Or, staying totally within VBA, using this for your second line instead...

s = Replace(s, "'", "20")

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top