Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Code problem with text box

Paul

First, you probably don't want to use the Change event because it fires
before the user is done entering their stuff. If you want to enter 15%
and
you type 0.15, the Change event fires like

0 fires . fires 1 fires 5 fires

Use the BeforeUpdate event to check that the value is valid. If it's
not,
you can set the Cancel argument to True which will cancel the update.
Then
use the AfterUpdate event to do your calculation.

Why your method doesn't work is hard to say without seeing the rest of
the
code. Maybe spvol isn't scoped properly.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Paul wrote:

I have a user form with a text box. The user enters a rate and a
return on assets figure is calculated. My problem is that when the
rate is blank, if the user zeroes it out, an overflow error occurs. I
think this is due to the fact that when it's blank a division by zero
is performed downstream. I tried to write some code to deal with this
but it doesn't seem to work. Any help would be appreciated.

Private Sub txtvolsp_Change()
If txtvolsp.Text = " " Then
spvol = 0.00001
Else
spvol = CLng(txtvolsp.Value)
End If
End Sub


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
Text format - setting text colour with code NDBC Excel Discussion (Misc queries) 6 July 1st 09 10:15 PM
Macro - Fixed text code needs replacing with variable text steven.holloway Excel Discussion (Misc queries) 3 July 22nd 08 03:57 PM
Convert a Number Code to a Text Code Traye Excel Discussion (Misc queries) 3 April 6th 07 09:54 PM
Code problem with text box Paul Excel Programming 1 April 20th 05 02:46 PM
Date problem from code to text box to spreadsheet Joe 90[_2_] Excel Programming 2 October 20th 03 11:18 PM


All times are GMT +1. The time now is 12:21 PM.

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

About Us

"It's about Microsoft Excel"