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

Hi,

This is because in order to use a function like CLng or CInt or CSng the
value you pass into the function must be numeric.

If you leave any of the textboxes blank then this throws an error as the
function (CSng etc) cannot convert an empty string into a numeric value.

So you need to check the values of the textboxes before you try to check them.

You can use code like:

if (vba.len(textbox1.value) 0 and vba.len(textbox2.value) 0 and
vba.len(textbox3.value) 0) then
If (vba.isnumeric(textbox1.value) and vba.isnumeric(textbox1.value) and
vba.isnumeric(textbox1.value) ) then
' ALL OK, so check if values ad up
else
' not numeric - is it a text value
msgbox "please enter numbers only in the fields",
vbexclamation+vbokonly
end if
else
msgbox "Please fill each field", vbexclamation+vbokonly
end if

HTH

Philip
"Lucifix" wrote:


Philips foruma works just well, but I get error if I leave all fields
empty. Do you have any idea to fix this?

Run-time error '13'.

Type mismatch


--
Lucifix
------------------------------------------------------------------------
Lucifix's Profile: http://www.excelforum.com/member.php...o&userid=29179
View this thread: http://www.excelforum.com/showthread...hreadid=495452


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
Simple Calculation Not Working JDM Excel Discussion (Misc queries) 2 August 30th 07 04:02 PM
PLEASE HELP--going crazy with a simple calculation diane Excel Worksheet Functions 3 November 14th 05 06:42 PM
Need help with a simple Time calculation Bjarne Hansen Excel Worksheet Functions 3 August 1st 05 03:21 PM
Need help with a simple Time calculation Bjarne Hansen Excel Discussion (Misc queries) 3 August 1st 05 08:22 AM
error in simple calculation? Tobias Excel Discussion (Misc queries) 4 March 4th 05 01:27 PM


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