Thanks:  0
Likes:  0

# Thread: ... Why is Excel saying 2 > 12?

1. ## ... Why is Excel saying 2 > 12?

Okay. I don't know if I'm just fried or if Excel is having an stroke or what, but here's my code:

Code:
```    FindMe = 2
FinalFind = 12
FinderLoop:
If FindMe < FinalFind Then
FindMe = FindMe + 1
GoTo FinderLoop
End If```
It's skipping over my If statement, in other words Excel is saying 2 > 12. In fact, if I change it to If FindMe > FinalFind, then it goes through.
Please tell me I'm just overlooking something stupid.

2. ## Re: ... Why is Excel saying 2 > 12?

It works fine for me.
Have you declared the FindMe and FinalFind variables in your code?

3. ## Re: ... Why is Excel saying 2 > 12?

Originally Posted by Technowolf
Okay. I don't know if I'm just fried or if Excel is having an stroke or what, but here's my code:

Code:
```    FindMe = 2
FinalFind = 12
FinderLoop:
If FindMe < FinalFind Then
FindMe = FindMe + 1
GoTo FinderLoop
End If```
It's skipping over my If statement, in other words Excel is saying 2 > 12. In fact, if I change it to If FindMe > FinalFind, then it goes through.
Your code works for me... the only way I can get it to do what you say it is doing for you is to Dim FindMe and FinalFind as String variables OR, if those variables are Variants, assign text values to them.

4. ## Re: ... Why is Excel saying 2 > 12?

Yup.

Code:
`Dim FindMe As String, FinalFind As String`

5. ## Re: ... Why is Excel saying 2 > 12?

That was my first guess, they're strings, in which case it would make sense. You'd need to post the entire code for us to get anywhere though.

Edit: Ah, just saw your reply. Declare them as Long, if they're going to be whole numbers anyway.

6. ## Re: ... Why is Excel saying 2 > 12?

So I shouldn't declare them as String? How come?

7. ## Re: ... Why is Excel saying 2 > 12?

Dim FindMe As String, FinalFind As String
So I shouldn't declare them as String? How come?
Numerically speaking, 2 comes before 12, but alphabetically speaking "12" comes before "2" since "1" comes before "2".
If you want them to behave like numbers, then you need to declare them as numbers.

8. ## Re: ... Why is Excel saying 2 > 12?

Joe4 is spot on, it must be interpreting one of those variables as string.

9. ## Re: ... Why is Excel saying 2 > 12?

Originally Posted by Technowolf
So I shouldn't declare them as String? How come?
Because you appear to be assigning numeric values to them, so declare them as a numeric data type (Long if they will always be whole numbers, Double if they will be floating point numbers).

10. ## Re: ... Why is Excel saying 2 > 12?

No, you shouldn't declare them as String. A String is a textual variable. It will try to make everything a string. Think of it as enclosing it in quotes. In fact if you look at the variable at run-time in the Locals window, it will be enclosed in quotes. To be able to evaluate it as a number, it must be declared as a number type, such as Long, Integer, Single, or Double (the latter two being types to handle decimals).

## User Tag List

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•