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

#### Technowolf

##### Board Regular
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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

#### Joe4

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

#### Rick Rothstein

##### MrExcel MVP
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.

#### Technowolf

##### Board Regular
Yup.

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

#### Zack Barresse

##### MrExcel MVP

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.

#### Technowolf

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

#### Joe4

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.

#### chicagocomputerclasses

##### Well-known Member
Joe4 is spot on, it must be interpreting one of those variables as string.

#### Rick Rothstein

##### MrExcel MVP
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).

#### Zack Barresse

##### MrExcel MVP
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).

Replies
1
Views
503
Replies
12
Views
316
Replies
6
Views
328
Replies
4
Views
814
Replies
0
Views
365

1,140,929
Messages
5,703,225
Members
421,285
Latest member
Bebek

### 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.

### Which adblocker are you using?

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

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