4 Replies Latest reply on Mar 9, 2017 6:40 AM by Deepak Gupta

    different from series of numbers

    Lasse Nielsen

      Hello forum,


      Is it possible for a macro to determine if a user input value is different from a series of numbers?


      Lets say the user can input any value he imagines, but the macro should only run if the number is equal to


      20, 25, 32, 40, 50, 63, 75, 90, 110 and a bunch more. Total of 30 numbers



      Something like this?

      If PPD.Text <> (number series) Then MsgBox "Error", vbOKOnly, "Value error"


      Or how do i go about this in the shortest amount of code?

        • Re: different from series of numbers
          Deepak Gupta

          Why don't you add a drop-down with the list of numbers and user can enter/pick from those. OR you can set up an IF condition in the macro to check for those numbers.


          Not fully sure (and how to do it) but I think you can create an array of those number and can check against that array too.

          • Re: different from series of numbers
            Peter Brinkhuis

            What is the task that you are trying to accomplish? It seems kind of strange that a used has to input 30 numbers and a macro only runs for that exact set of numbers. Does the order count? Do you have an array of numbers, or strings?


            There is no array comparator in VBA, but I found a comment about using the Join command. Join all the numbers to a single string (add a separator) and compare those strings. You won't know what didn't match, but maybe that's ok.

            • Re: different from series of numbers
              Lasse Nielsen

              Maybe i didn't explained it correctly.


              First of all the user only types in one number. For instance 32. That number matches on of the numbers in the number series and the macro continues. If the user had typed 45, the macro should then display an error since it does NOT match any numbers in the series.


              The reason for not using a drop down is because it faster to type the number using the num pad vs click and point with the mouse. Also we know the number series, since we use it every day. The check against the number series is only to prevent typos.