![]() |
If/then code problem
I have a userform that contains a 'start month' text box and an 'en month' text box for input. The value in the start month textbox must be equal to or less than th value in th end month text box. I need to generate an error message if user accidentaly enters a valu in the 'end month' tbox that is greater than the end month value I have written the following code If txtStartMonth.Value txtEndMonth.Value then MsgBox "start month must be equal to or less than value of end month" The problem: Say end month value is 60 As soon as I enter a value in the start month text box greater than 6 the error message displays? I must be doing something basically wrong. Any help appreciated Peter (new to VBA, and learning the hard way! -- peter.thompso ----------------------------------------------------------------------- peter.thompson's Profile: http://www.excelforum.com/member.php...fo&userid=2968 View this thread: http://www.excelforum.com/showthread.php?threadid=49609 |
If/then code problem
Peter,
You are doing a string comparison by the looks of it. Try If cint(txtStartMonth.Text) cint(txtEndMonth.Text) Robin Hammond www.enhanceddatasystems.com "peter.thompson" <peter.thompson.20odwy_1135647901.9001@excelforu m-nospam.com wrote in message news:peter.thompson.20odwy_1135647901.9001@excelfo rum-nospam.com... I have a userform that contains a 'start month' text box and an 'end month' text box for input. The value in the start month textbox must be equal to or less than the value in th end month text box. I need to generate an error message if user accidentaly enters a value in the 'end month' tbox that is greater than the end month value I have written the following code If txtStartMonth.Value txtEndMonth.Value then MsgBox "start month must be equal to or less than value of end month" The problem: Say end month value is 60 As soon as I enter a value in the start month text box greater than 6, the error message displays? I must be doing something basically wrong. Any help appreciated Peter (new to VBA, and learning the hard way!) -- peter.thompson ------------------------------------------------------------------------ peter.thompson's Profile: http://www.excelforum.com/member.php...o&userid=29686 View this thread: http://www.excelforum.com/showthread...hreadid=496092 |
If/then code problem
Thanks Robin..fixed it right up! Cheers, Peter (new to VBA...slowly getting it! -- peter.thompso ----------------------------------------------------------------------- peter.thompson's Profile: http://www.excelforum.com/member.php...fo&userid=2968 View this thread: http://www.excelforum.com/showthread.php?threadid=49609 |
All times are GMT +1. The time now is 10:25 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com