ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA - not working (https://www.excelbanter.com/excel-programming/296966-vba-not-working.html)

ajliaks[_18_]

VBA - not working
 
Hi

I am trying the way you told me, but is not working right. I guess I a
missing something.

when I run it, I allways get the MsgBox "Value must be between 0.0
1.0", no mather the value.

Private Sub PercentTB_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Min As Variant
Dim Max As Variant

PercentTB.Value = Format(CSng(PercentTB.Value), "##.#%")

Min = Format(CSng(0), "##.#%")
Max = Format(CSng(1), "##.#%")

If (PercentTB.Value < Min) Or (PercentTB.Value Max) Then
MsgBox "Value must be between 0.0 - 1.0", vbOKOnly
Cancel = True
End If
End Su

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

VBA - not working
 
You really should keep top one thread. To expect everyone to keep up with
your multiple postings is totally unreasonable.

What is your total code looking like now? What are you inputting and what do
you want?

--

HTH

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

"ajliaks " wrote in message
...
Hi

I am trying the way you told me, but is not working right. I guess I am
missing something.

when I run it, I allways get the MsgBox "Value must be between 0.0 -
1.0", no mather the value.

Private Sub PercentTB_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Min As Variant
Dim Max As Variant

PercentTB.Value = Format(CSng(PercentTB.Value), "##.#%")

Min = Format(CSng(0), "##.#%")
Max = Format(CSng(1), "##.#%")

If (PercentTB.Value < Min) Or (PercentTB.Value Max) Then
MsgBox "Value must be between 0.0 - 1.0", vbOKOnly
Cancel = True
End If
End Sub


---
Message posted from http://www.ExcelForum.com/




Tom Ogilvy

VBA - not working
 
You are going to have to decide what you want the user to enter in the cell.
What is acceptable

Which
..50
or
50
or
50%
or multiple

Then you have to test for what was entered and decide what you want to do
with it.

Whatever is in the textbox will be a string, so you don't want to compare a
string to a number. You will need to convert the string to a number and do
the comparison.

It appears you want the value entered to be between 0.0 and 1.0. If so, you
don't want to turn it into a percentage before you do the check.


Private Sub PercentTB_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Min As Single
Dim Max As Single


Min = Format(CSng(0), "##.#%")
Max = Format(CSng(1), "##.#%")

If (csng(PercentTB.Value) < Min) Or (csng(PercentTB.Value) Max) Then
MsgBox "Value must be between 0.0 - 1.0", vbOKOnly
Cancel = True
PercentTB.Value = ""
End If

PercentTB.Value = Format(CSng(PercentTB.Value), "##.#%")

End Sub

--
Regards,
Tom Ogilvy




"ajliaks " wrote in message
...
Hi

I am trying the way you told me, but is not working right. I guess I am
missing something.

when I run it, I allways get the MsgBox "Value must be between 0.0 -
1.0", no mather the value.

Private Sub PercentTB_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Min As Variant
Dim Max As Variant

PercentTB.Value = Format(CSng(PercentTB.Value), "##.#%")

Min = Format(CSng(0), "##.#%")
Max = Format(CSng(1), "##.#%")

If (PercentTB.Value < Min) Or (PercentTB.Value Max) Then
MsgBox "Value must be between 0.0 - 1.0", vbOKOnly
Cancel = True
End If
End Sub


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 03:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com