0

I made a simple vba application that allows a user to enter data into excel. The data that's being entered had to be >= 1.99 ohms and can be 3.00 or higher. Everything works great and it's been in use for over a year now. However, recently a user fat fingered a decimal point and didn't catch it until they entered the number. VBA didn't like that and errored out. The format they entered looked like so: '.2.34'. I can't seem to figure out how to avoid this. Any suggestions?

I've tried using:

If Res.value <> Format(Number, "#.##") Then
    Msgbox ("blah blah")
    Res.Value = ""
    Exit Sub
End if

This blocks those entries, but it also blocks correct entries.

3
  • Take a look at this stackoverflow.com/questions/23655251/decimal-tryparse-in-vba
    – eren
    Jun 27, 2018 at 6:12
  • 2
    You can use IsNumeric(Res.Value) to check if it is a number and if it is a number you can check afterwards If Res.Value => 1.99 And Res.Value < 3.00 or something similar.
    – Pᴇʜ
    Jun 27, 2018 at 6:29
  • This worked, thank you for your help!
    – Jg112
    Jun 27, 2018 at 11:07

1 Answer 1

0

Maybe you could add Data Validation rules on the typical ranges. Try this: Data > Data Tools > Data Validation

Not the answer you're looking for? Browse other questions tagged or ask your own question.