Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code Problem Tim Excel Programming 2 June 24th 05 10:29 PM
Problem with the end of this code EMoe[_29_] Excel Programming 2 June 13th 05 12:44 PM
Code Problem TC[_8_] Excel Programming 8 November 30th 04 07:09 PM
VBA code problem excelnoob[_2_] Excel Programming 1 July 5th 04 01:31 PM
Problem with this code Jonsson[_8_] Excel Programming 2 April 21st 04 01:07 PM


All times are GMT +1. The time now is 07:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"