View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Robin Hammond[_2_] Robin Hammond[_2_] is offline
external usenet poster
 
Posts: 575
Default 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