... Why is Excel saying 2 > 12?

Technowolf

Board Regular
Joined
Aug 28, 2014
Messages
181
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.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
It works fine for me.
Have you declared the FindMe and FinalFind variables in your code?
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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).
 
Upvote 0
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).
 
Upvote 0

Forum statistics

Threads
1,213,483
Messages
6,113,919
Members
448,533
Latest member
thietbibeboiwasaco

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top