The declarations for my code are set so that I receive decimal values for the values of x and y
I'm using this code;
The below line of code returns Qty1 values in quotation marks, which causes a problem at "If Qty1.value > x Then"
and is comparing values in quotation marks to values without quotation marks at this line of code;
The end result is that a lower value in quote marks still shows as greater than x
I'd like to rid the quote marks coming from;
Can someone please correct this?
Hope I've provided enough information.
I'm using this code;
VBA Code:
Private Sub Prct1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'=====================================================
' Immediately checks the percent and quantity entered
' and returns msgbox if entries cause excess of 100%
'=====================================================
Dim Lr1 As Long
Dim ws As Worksheet
Dim x
Dim y
Set ws = ActiveWorkbook.Worksheets("Main")
Lr1 = ws.Cells(Rows.Count, "A").End(xlUp).Row
If Prct1.Text <> "" Then
Qty1.Value = Application.VLookup((Me.CBox1.Value), ws.Range("A4:B" & Lr1), 2, 0) * Prct1.Value / 100
x = Application.VLookup((Me.CBox1.Value), ws.Range("A4:G" & Lr1), 7, 0)
y = Application.VLookup((Me.CBox1.Value), ws.Range("A4:H" & Lr1), 8, 0)
y = Format(y, "0.000%")
If Qty1.Value > x Then
MsgBox "The Percent/Quantity entered for this item - " & CBox1.Text & vbCr & _
"will exceed a 100% completion rate/value." & vbCr & vbCr & _
"The maximum Percentage remaining for this item is; " & y & vbCr & _
"The maximum Quantity remaining for this item is; " & x & vbCr & _
"Please adjust.", , "100% Valuation Exceeded"
Application.EnableEvents = False
Qty1.Text = ""
Prct1.Text = ""
Me.Qty1.SetFocus
Application.EnableEvents = True
Exit Sub
End If
Qty1.BackColor = RGB(205, 205, 205) ' ---- Gray
End If
End Sub
The below line of code returns Qty1 values in quotation marks, which causes a problem at "If Qty1.value > x Then"
VBA Code:
Qty1.Value = Application.VLookup((Me.CBox1.Value), ws.Range("A4:B" & Lr1), 2, 0) * Prct1.Value / 100
and is comparing values in quotation marks to values without quotation marks at this line of code;
VBA Code:
If Qty1.value > x Then
The end result is that a lower value in quote marks still shows as greater than x
I'd like to rid the quote marks coming from;
VBA Code:
Qty1.Value = Application.VLookup((Me.CBox1.Value), ws.Range("A4:B" & Lr1), 2, 0) * Prct1.Value / 100
Can someone please correct this?
Hope I've provided enough information.