Issue on if function > "45"

jptaz

New Member
Joined
May 1, 2020
Messages
46
Office Version
  1. 2010
Platform
  1. Windows
Hello,

I have this code to enable and change the back color to white of a combo box if the value any of 3 other textboxes equals or is higher to 45. Otherwise, the combo box stays disable and gray.

The problem is that if I enter the following numbers (5, 6, 7, 8, 9), the combox box is being enabled. Any other numbers below 45, it stays disabled...

Do you have any idea why? How do I fix this?

VBA Code:
Private Sub Condition_1()
    If Controls.Item("Reg549").Value >= "45" Or Controls.Item("Reg550").Value >= "45" Or Controls.Item("Reg551").Value >= "45" Then
        Controls.Item("Reg552").Enabled = True
        Controls.Item("Reg552").BackColor = "&H80000005"
    Else
        Controls.Item("Reg552").Enabled = False
        Controls.Item("Reg552").BackColor = "&H80000004"
    End If
End Sub

Private Sub Reg549_AfterUpdate()
    Call Condition_1
End Sub
Private Sub Reg550_AfterUpdate()
    Call Condition_1
End Sub
Private Sub Reg551_AfterUpdate()
    Call Condition_1
End Sub

thank you

JP
 
You're welcome jptaz.

VBA.IIF is a one line If-Then-Else instruction being used to force the blank textboxes to be seen as zeros.

With some testing I figured out the VBA was treating a mixture of letters, numbers and blanks the same way text would be sorted A->Z.
ie: numbers - letters - blanks
so letters and blanks would always be larger than 45.
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,215,219
Messages
6,123,684
Members
449,116
Latest member
HypnoFant

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