Excel VBA - Quick question

  • Thread starter Thread starter ajlove20
  • Start date Start date
A

ajlove20

Hi,

How would I write a Select Case statement that reads in an array o
numbers and check to see if each of them are integers and creates a
error message for the numbers that are not integers.

Thanks in advance.

a
 
What makes you think it is a Select Case.

For i = LBound(myArray, 1) To UBound(myArray, 1)
If Not IsNumeric(myArray(i)) Then
smsg = smsg & "Entry " & i & ", value " & myArray(i) & vbCrLf
End If
Next i

MsgBox smsg, vbInformation, "Invalid entries"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Hi,

Thank you. The only reason I was using Select Case was b/c I had a
assignment where I was supposed to use it. There were a list of tes
to do to the numbers read in. Here is an example of what I had t
do.

There are a list of numbers in column A such as:

45
53
22
220
365
698
1580
1900

Then an inputbox will pop up and ask the user to enter a number. Th
number entered will then be checked to make sure it is an integer
between 0 and 2000, and some other tests (I was told to use Select Cas
to do this). Once this is verified, the program is supposed to compar
the number entered with the numbers in the array to see if they match.

Thank you again.

a
 
You could frig a Select Case into it

For i = LBound(myArray, 1) To UBound(myArray, 1)
Select Case myArray(i)
Case < 20
smsg = smsg & "Entry " & i & ", value " & myArray(i) & " is
<20" & vbCrLf
Case < 50
smsg = smsg & "Entry " & i & ", value " & myArray(i) & " is
<50" & vbCrLf
Case < 100
smsg = smsg & "Entry " & i & ", value " & myArray(i) & " is
<100" & vbCrLf
Case Else
smsg = smsg & "Entry " & i & ", value " & myArray(i) & " is
=100" & vbCrLf
End Selct
Next i

MsgBox smsg, vbInformation, "Invalid entries"

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top