Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Userform TextBox

Hiya,

This is my code;

Private Sub OKButton_Click()

' Make sure a name is entered
If TextName.Text = "" Then
MsgBox "You must enter a valid numeric value."
TextName.SetFocus
Exit Sub

End If

If TextName.Text ActiveCell.Offset(-1, 0) Then
MsgBox "Value cannot be greater than hours in the day!"
TextName.Text = ""
TextName.SetFocus
Exit Sub

End If

' Transfer the name
ActiveCell = TextName.Text

'

' Clear the controls for the next entry
TextName.Text = ""
TextName.SetFocus
End Sub

My problem is the second test that checks the value entered, if it is
greater than the offset cell then msg box appears and the value is rejected,
If offest cell value is say 7.5, and I enter 8.0 then value is rejected as
it should, but if I enter 10 then the value is accepted, but it should be
rejected is value is still greater than offset cell, But I can't figure out
why.

Where am I going wrong?

Any help is very much appricated.

Regards

Laddie


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Userform TextBox

You need to change TextName.Text it is a string. I think you want is
val(TextName.txt) which will convert the number which is a string to an
actual numnber.

"LaDdIe" wrote:

Hiya,

This is my code;

Private Sub OKButton_Click()

' Make sure a name is entered
If TextName.Text = "" Then
MsgBox "You must enter a valid numeric value."
TextName.SetFocus
Exit Sub

End If

If TextName.Text ActiveCell.Offset(-1, 0) Then
MsgBox "Value cannot be greater than hours in the day!"
TextName.Text = ""
TextName.SetFocus
Exit Sub

End If

' Transfer the name
ActiveCell = TextName.Text

'

' Clear the controls for the next entry
TextName.Text = ""
TextName.SetFocus
End Sub

My problem is the second test that checks the value entered, if it is
greater than the offset cell then msg box appears and the value is rejected,
If offest cell value is say 7.5, and I enter 8.0 then value is rejected as
it should, but if I enter 10 then the value is accepted, but it should be
rejected is value is still greater than offset cell, But I can't figure out
why.

Where am I going wrong?

Any help is very much appricated.

Regards

Laddie


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Userform TextBox

Try

If CDbl(TextName.Text) ActiveCell.Offset(-1, 0) Then


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"LaDdIe" wrote in message
...
Hiya,

This is my code;

Private Sub OKButton_Click()

' Make sure a name is entered
If TextName.Text = "" Then
MsgBox "You must enter a valid numeric value."
TextName.SetFocus
Exit Sub

End If

If TextName.Text ActiveCell.Offset(-1, 0) Then
MsgBox "Value cannot be greater than hours in the day!"
TextName.Text = ""
TextName.SetFocus
Exit Sub

End If

' Transfer the name
ActiveCell = TextName.Text

'

' Clear the controls for the next entry
TextName.Text = ""
TextName.SetFocus
End Sub

My problem is the second test that checks the value entered, if it is
greater than the offset cell then msg box appears and the value is
rejected,
If offest cell value is say 7.5, and I enter 8.0 then value is rejected
as
it should, but if I enter 10 then the value is accepted, but it should be
rejected is value is still greater than offset cell, But I can't figure
out
why.

Where am I going wrong?

Any help is very much appricated.

Regards

Laddie




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Userform TextBox



"Bob Phillips" wrote:

Try

If CDbl(TextName.Text) ActiveCell.Offset(-1, 0) Then


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"LaDdIe" wrote in message
...
Hiya,

This is my code;

Private Sub OKButton_Click()

' Make sure a name is entered
If TextName.Text = "" Then
MsgBox "You must enter a valid numeric value."
TextName.SetFocus
Exit Sub

End If

If TextName.Text ActiveCell.Offset(-1, 0) Then
MsgBox "Value cannot be greater than hours in the day!"
TextName.Text = ""
TextName.SetFocus
Exit Sub

End If

' Transfer the name
ActiveCell = TextName.Text

'

' Clear the controls for the next entry
TextName.Text = ""
TextName.SetFocus
End Sub

My problem is the second test that checks the value entered, if it is
greater than the offset cell then msg box appears and the value is
rejected,
If offest cell value is say 7.5, and I enter 8.0 then value is rejected
as
it should, but if I enter 10 then the value is accepted, but it should be
rejected is value is still greater than offset cell, But I can't figure
out
why.

Where am I going wrong?

Any help is very much appricated.

Regards

Laddie





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Userform TextBox

Thanks to Both Joel & Bob,

Bob ,

If CDbl(TextName.Text) ActiveCell.Offset(-1, 0) Then

What does CDbl actually do?

"Bob Phillips" wrote:

Try

If CDbl(TextName.Text) ActiveCell.Offset(-1, 0) Then


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"LaDdIe" wrote in message
...
Hiya,

This is my code;

Private Sub OKButton_Click()

' Make sure a name is entered
If TextName.Text = "" Then
MsgBox "You must enter a valid numeric value."
TextName.SetFocus
Exit Sub

End If

If TextName.Text ActiveCell.Offset(-1, 0) Then
MsgBox "Value cannot be greater than hours in the day!"
TextName.Text = ""
TextName.SetFocus
Exit Sub

End If

' Transfer the name
ActiveCell = TextName.Text

'

' Clear the controls for the next entry
TextName.Text = ""
TextName.SetFocus
End Sub

My problem is the second test that checks the value entered, if it is
greater than the offset cell then msg box appears and the value is
rejected,
If offest cell value is say 7.5, and I enter 8.0 then value is rejected
as
it should, but if I enter 10 then the value is accepted, but it should be
rejected is value is still greater than offset cell, But I can't figure
out
why.

Where am I going wrong?

Any help is very much appricated.

Regards

Laddie







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
Userform textbox help [email protected] Excel Programming 1 September 17th 06 08:27 AM
TEXTBOX in USERFORM RUUD VAN DEURSEN Excel Programming 5 March 1st 05 03:36 PM
userform textbox Phil Excel Worksheet Functions 5 January 16th 05 06:59 PM
Textbox in userform shaharul[_6_] Excel Programming 3 April 15th 04 12:54 PM
UserForm TextBox to ActiveSheet TextBox over 256 characters Dan E[_2_] Excel Programming 1 July 28th 03 07:36 PM


All times are GMT +1. The time now is 12:10 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"