Error Checking with Input Box

kb24gunner10

New Member
Joined
Sep 29, 2014
Messages
9
Hi,

I have an application which has a long list of prices. I have a sub that asks the user to enter a sample size out of the entire population of prices and then returns the average of a random sample of prices.

I want to use a double variable to take the price entered by the user instead of the variant type. So I have error checking turned on right before the input box stating "on error GoTo errorHandler:" and turned off right after the input box stating "on error GoTo 0" if the user enters a string into the input box rather than a number.

In the error handler, a message box displays a message saying you haven't entered a valid numeric value and then the next line says GoTo sample: (where "sample:" is the label right above the "on error GoTo errorhandler:" line is).

My problem is the error handler works fine if I enter text into the input box the first time but doesn't work the second time I enter text and it displays the usual run time error box the second time around. How would I get it to work to continuously not display the run time error box when text is entered?

I've gotten it to work using a variant data type for the variable that takes the input, but is there a way to get the error checker to work.

The code looks something like this

sample:
on error GoTo errorhandler:
sample = inputbox("enter sample size")
on error goto 0

lines of code

exit sub

errorhandler:
msgbox "enter numeric value"
GoTo sample:

end sub

Any help would be appreciated.
 
I ended up using the regular input box, set the data type as variant and did error checking with if statements rather than error handlers.

I would be curious to see the final code you are using for this (loops, if any, and all).
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top