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


I have a created a financial model which includes TextBoxes for the use
to input certain assumptions. If the user does not input a number i
TextBoxes, which are inserted in the spreadsheet, the program creates
error. For example, if the user enters ".50" it works fine but if th
user enters "..50" by accident it causes a debug error. How can
protect from this happening?

Thank

--
bforster
-----------------------------------------------------------------------
bforster1's Profile: http://www.excelforum.com/member.php...fo&userid=1177
View this thread: http://www.excelforum.com/showthread.php?threadid=27448

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel VBA - TextBox Error

Hi
You may use the IsNumeric function together with the AfterUpdate event of
your textbox:
Private Sub TextBox1_AfterUpdate()
If TextBox1 < "" And Not IsNumeric(TextBox1) Then
MsgBox "Number expected here!" & vbLf & "please try again"
TextBox1.Text = ""
End If
End Sub

HTH
Cordially
Pascal

"bforster1" a écrit dans le message
de ...

I have a created a financial model which includes TextBoxes for the user
to input certain assumptions. If the user does not input a number in
TextBoxes, which are inserted in the spreadsheet, the program creates a
error. For example, if the user enters ".50" it works fine but if the
user enters "..50" by accident it causes a debug error. How can i
protect from this happening?

Thanks


--
bforster1
------------------------------------------------------------------------
bforster1's Profile:

http://www.excelforum.com/member.php...o&userid=11771
View this thread: http://www.excelforum.com/showthread...hreadid=274486



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Excel VBA - TextBox Error

Dim cDots As Long

Private Sub txtRank_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If cDots 1 Then
MsgBox "Too manuy dots"
Cancel = True
End If
End Sub

Private Sub txtRank_Change()
cDots = Len(txtRank.Text) - Len(Replace(txtRank.Text, ".", ""))
End Sub

Private Sub txtRank_Enter()
cDots = 0
End Sub

'---------------------------------------------------------------------------
Private Sub txtRank_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'---------------------------------------------------------------------------

Select Case KeyAscii
Case Asc("0") To Asc("9"): 'OK
Case Asc("."): cDots = cDots + 1
Case Else: KeyAscii = 0
End Select
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"bforster1" wrote in message
...

I have a created a financial model which includes TextBoxes for the user
to input certain assumptions. If the user does not input a number in
TextBoxes, which are inserted in the spreadsheet, the program creates a
error. For example, if the user enters ".50" it works fine but if the
user enters "..50" by accident it causes a debug error. How can i
protect from this happening?

Thanks


--
bforster1
------------------------------------------------------------------------
bforster1's Profile:

http://www.excelforum.com/member.php...o&userid=11771
View this thread: http://www.excelforum.com/showthread...hreadid=274486



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
Runtime error textbox problem - help required N E Body Excel Programming 3 October 19th 04 10:27 PM
How to move cursor from one textbox control to another textbox con Tom Ogilvy Excel Programming 1 September 16th 04 03:42 PM
How to move cursor from one textbox control to another textbox con KMoore007 Excel Programming 0 September 16th 04 02:47 PM
Textbox error checK problems Jako[_51_] Excel Programming 1 July 31st 04 10:47 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 05:16 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"