Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8204817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:00:45+00:00 2026-06-07T08:00:45+00:00

I have the following code to check values entered into two input boxes, if

  • 0

I have the following code to check values entered into two input boxes, if both values are zero then the MsgBox should display “Stop!” (I will change this later to exiting the sub but I am using a MsgBox for testing)

From testing I’ve seen these results:

  • A zero in both strings produces the expected message box.

  • A non zero in the first string followed by any non zero value in the second string does nothing (as expected).

  • A zero in the first string followed by a second string value equal to or greater than 10 produces the message box (unexpected).

I’ve also noticed that if the second string is 6-9 it is displayed as x.00000000000001%. I think this is a floating point issue and could be related? This behaviour occurs without the IF... InStr function too.

Option Explicit
Sub Models()
    Dim MinPer As String, MaxPer As String, Frmula As String
    Dim Data As Worksheet, Results As Worksheet
    Set Data = Sheets("Data")
    Set Results = Sheets("Results")

    Application.ScreenUpdating = False

    MinPer = 1 - InputBox("Enter Minimum Threshold Percentage, do not include the % symbol", _
    "Minimum?") / 100
    MaxPer = 1 + InputBox("Enter Maximum Threshold Percentage, do not include the % symbol", _
    "Maximum?") / 100


    If (InStr(MinPer, "0") = 0) And (InStr(MaxPer, "0") = 0) Then
    MsgBox "STOP!"
    End If

    ' Remainder of code...

This is the most interesting problem I’ve come across so far in VBA and welcome any discussion about it.

Edit: I use this code to display on screen the paramaters for the end-user to see. Hence how I noticed the .00000000001% issue:

    .Range("D2").Value = "Min is " & 100 - MinPer * 100 & "%"
    .Range("D3").Value = "Max is " & MaxPer * 100 - 100 & "%"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:00:46+00:00Added an answer on June 7, 2026 at 8:00 am

    Two things

    1) Declare MinPer, MaxPer as Long or a Double and not a String as you are storing outputs from a calculation

    2) Don’t directly use the InputBox in the calculations. Store them in a variable and then if the input is valid then use them in the calculation

    Dim MinPer As Double, MaxPer As Double, Frmula As String
    Dim Data As Worksheet, Results As Worksheet
    Dim n1 As Long, n2 As Long
    
    Set Data = Sheets("Data")
    Set Results = Sheets("Results")
    
    Application.ScreenUpdating = False
    
    On Error Resume Next
    n1 = Application.InputBox(Prompt:="Enter Minimum Threshold Percentage, do not include the % symbol", _
    Title:="Minimum?", Type:=1)
    On Error GoTo 0
    
    If n1 = False Then
        MsgBox "User cancelled"
        Exit Sub
    End If
    
    On Error Resume Next
    n2 = Application.InputBox(Prompt:="Enter Maximum Threshold Percentage, do not include the % symbol", _
    Title:="Maximum?", Type:=1)
    On Error GoTo 0
    
    If n2 = False Then
        MsgBox "User cancelled"
        Exit Sub
    End If
    
    If n1 = 0 And n2 = 0 Then
        MsgBox "STOP!"
    End If
    
    MinPer = 1 - (Val(n1) / 100)
    MaxPer = 1 + (Val(n2) / 100)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: INSERT IGNORE INTO unsubscribes (email) VALUES (john@john.com),(kevin@kevin.com),(mike@mike.com),(another@gmail.com) but it
I have the following code that pushes check-box values to an array. I want
I have the following code. I want to add/remove check-box values to an array
I have the following code: foreach (ListItem item in check.Items) { if (item.Selected) {
I have the following piece of code where check is for char type do{
I have written the following code for inserting video bytes into the database DBAdapter.java
I have a 'strange' problem, the following code converts the location lat value into
I have the following code to check if my tab is liked by the
I have the following code: public function createNewGuide($userID,$guideName) { $sql = INSERT INTO myTable(name,
I have the following code //check out the tags, if it allready exist update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.