< returning wrong result

Dean76

New Member
Joined
Apr 17, 2016
Messages
37
I will firstly apologise for the messy code.......

I am working from a userform, and have the textboxes, here named f1b2 and f1b3, I am wanting to cancel the exit from f1b2 if the number entered in the box is smaller than the number in f1b3 however in the following example the number in f1b2 is 12 and f1b3 is 6, thefore f1b2n < f1b3n should be false, however it appears to be returning a true value - can anyone assist?

Private Sub f1b2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim f1b3n, f1b2n, f1b1n As Long
Dim answer, answer2 As Integer
If IsNumeric(f1b3.Value) = True Then
f1b3n = f1b3.Value
Else
f1b3n = 1000
End If
If IsNumeric(f1b2.Value) = True Then
f1b2n = f1b2.Value
Else
f1b2n = 1000
End If
If f1b2.Value <> "" Then
If f1b1.Value = "" Then GoTo LASTONEf1b2
If f1b2n < f1b3n Then 'this line is where i am failing - f1b2n is 12 and f1b3n is 6 however it appears to be returning true as the msgbox pops up every time.....
answer2 = MsgBox("Lower", vbQuestion + vbYesNo + vbDefaultButton2, "Higher")
If answer2 = vbNo Then
Cancel = True
Exit Sub
End If
End If
End If
LASTONEf1b2:
If f1b2.Value = "" Then f1b2.Value = "None"
End Sub

I hope it's not just me being stupid somewhere..........
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Text boxes contain text not numbers, which is why you get true, you need to convert them like
VBA Code:
If Val(f1b2n) < Val(f1b3n) Then
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,540
Messages
6,120,107
Members
448,945
Latest member
Vmanchoppy

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