ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   converting date from a textbox to a date format (https://www.excelbanter.com/excel-programming/292029-converting-date-textbox-date-format.html)

neowok[_17_]

converting date from a textbox to a date format
 
not as easy as it may sound because I currently have 2 columns in dat
format of dd-mmm-yy i.e. 05-Jan-04 and using cdate to convert from th
text box only seems to put it into dd/mm/yyyy format. I would reall
like to keep the dd-mmm-yy format that is used in the columns as i
makes it easier to see than 05/02/2004 when you have a big list o
dates.

So I need a way of converting the text the user types into the text bo
into date format dd-mmm-yy so that i can use autofilter to search it

--
Message posted from http://www.ExcelForum.com


Bernie Deitrick

converting date from a textbox to a date format
 
neo,

Try something like

myDateStr = Format(CDate(Textbox.Text), "dd-mmm-yyyy")

HTH,
Bernie
MS Excel MVP

"neowok " wrote in message
...
not as easy as it may sound because I currently have 2 columns in date
format of dd-mmm-yy i.e. 05-Jan-04 and using cdate to convert from the
text box only seems to put it into dd/mm/yyyy format. I would really
like to keep the dd-mmm-yy format that is used in the columns as it
makes it easier to see than 05/02/2004 when you have a big list of
dates.

So I need a way of converting the text the user types into the text box
into date format dd-mmm-yy so that i can use autofilter to search it.


---
Message posted from http://www.ExcelForum.com/




neowok[_18_]

converting date from a textbox to a date format
 
ok ill give it a try monday

thank

--
Message posted from http://www.ExcelForum.com


neowok[_19_]

converting date from a textbox to a date format
 
just tried that but isnt working, code i used was

Private Sub CommandButton4_Click()
Dim mydatestr As String
mydatestr = Format(CDate(TextBox2.value), "dd-mmm-yyyy")
Range("J23").Value = mydatestr
Me.Range("mytables").AutoFilter 6, mydatestr, _
Operator:=xlAnd
End Sub

only way ive got it to return a result so far is by

Me.Range("mytables").AutoFilter 6, cdate(textbox2.text), _
Operator:=xlAnd but i had to convert the column to the first dat
format *dd/mm/yyyy which seems to be what cdate converts to

--
Message posted from http://www.ExcelForum.com


Bernie Deitrick

converting date from a textbox to a date format
 
Neowok,

Your code worked fine for me if:

1) the entire column J was formated custom dd-mmm-yyyy
2) I removed the Me. before the autofilter method.

HTH,
Bernie
MS Excel MVP

"neowok " wrote in message
...
just tried that but isnt working, code i used was

Private Sub CommandButton4_Click()
Dim mydatestr As String
mydatestr = Format(CDate(TextBox2.value), "dd-mmm-yyyy")
Range("J23").Value = mydatestr
Me.Range("mytables").AutoFilter 6, mydatestr, _
Operator:=xlAnd
End Sub

only way ive got it to return a result so far is by

Me.Range("mytables").AutoFilter 6, cdate(textbox2.text), _
Operator:=xlAnd but i had to convert the column to the first date
format *dd/mm/yyyy which seems to be what cdate converts to.


---
Message posted from http://www.ExcelForum.com/




neowok[_22_]

converting date from a textbox to a date format
 
ahh thanks, ill try removing the ME then (dont know exactly what that
for anyway

--
Message posted from http://www.ExcelForum.com



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

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