Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hi, I have a user form on a worksheet that contains 2 text boxes, one o the text boxes is populated with a date by means of a calendar control and the other textbox is populated with a string value that correspond to the year (2005, 2006, 2007 etc) when the userform is initialised. command button enters these 2 values onto the sheet. I need to use the command button that when clicked will compare th date value in the one textbox to the year string value in the othe textbox [If that makes sense]. So, for example, preventing a date i 2006 being entered in 2005. Can anyone help me out with the correct way of doing this? Should I b using cDate to convert the date value to a string value befor comparing the 2 string values? Any help would be appreciated. Be -- benjammin ----------------------------------------------------------------------- benjammind's Profile: http://www.excelforum.com/member.php...fo&userid=1821 View this thread: http://www.excelforum.com/showthread.php?threadid=38431 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Ben,
The VBA function DatePart("yyyy", <your date here) will return the year portion of a specified date. You can then compare this against the year entered by the user to determine if they are the same. Here's one way of setting it up: If DatePart("yyyy", TextBox1.Text) < CLng(TextBox2.Text) Then ''' Error! End If -- Rob Bovey, Excel MVP Application Professionals http://www.appspro.com/ * Take your Excel development skills to the next level. * Professional Excel Development http://www.appspro.com/Books/Books.htm "benjammind" wrote in message ... Hi, I have a user form on a worksheet that contains 2 text boxes, one of the text boxes is populated with a date by means of a calendar control, and the other textbox is populated with a string value that corresponds to the year (2005, 2006, 2007 etc) when the userform is initialised. A command button enters these 2 values onto the sheet. I need to use the command button that when clicked will compare the date value in the one textbox to the year string value in the other textbox [If that makes sense]. So, for example, preventing a date in 2006 being entered in 2005. Can anyone help me out with the correct way of doing this? Should I be using cDate to convert the date value to a string value before comparing the 2 string values? Any help would be appreciated. Ben -- benjammind ------------------------------------------------------------------------ benjammind's Profile: http://www.excelforum.com/member.php...o&userid=18217 View this thread: http://www.excelforum.com/showthread...hreadid=384313 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Comparing the first 2 characters of a coloumn to a string | Excel Worksheet Functions | |||
Comparing String Values | Excel Programming | |||
Comparing String Values | Excel Programming | |||
Comparing String Values | Excel Programming | |||
Question about comparing mixed case string values | Excel Programming |