ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Converting Dates (https://www.excelbanter.com/excel-programming/407772-converting-dates.html)

wutzke

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


Gary''s Student

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

--
Gary''s Student - gsnu200773


"wutzke" wrote:

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



Leith Ross[_2_]

Converting Dates
 
On Mar 16, 7:19 am, wutzke wrote:
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

Rick Rothstein \(MVP - VB\)[_1498_]

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

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

Rick


"Gary''s Student" wrote in message
...
Sub qwerty()
s = "Feb '08 "
s = Application.WorksheetFunction.Substitute(s, "'", "20")
MsgBox (DateValue(s))
End Sub

--
Gary''s Student - gsnu200773


"wutzke" wrote:

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





All times are GMT +1. The time now is 08:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com