Stephenosn
Board Regular
- Joined
- Jun 2, 2015
- Messages
- 52
Hello all,
I'm working on a userform and am setting up some insurance the users enter the required data. I have a three text boxes: tbMaterial, tbQty and tbCost. There is a index match function for tbMaterials that fills in the cost if its a material we already have the price for. If we do not have the price then the user needs to fill out the cost. My code doesn't appear to make a difference if tbMaterials value matches a value in the range or not. For Ref_Appliance I'm using the following.
The code I'm trying to use for validation is as follows.
Please let me know if you know of a way to tackle my problem.
Thank you for having a look,
John
I'm working on a userform and am setting up some insurance the users enter the required data. I have a three text boxes: tbMaterial, tbQty and tbCost. There is a index match function for tbMaterials that fills in the cost if its a material we already have the price for. If we do not have the price then the user needs to fill out the cost. My code doesn't appear to make a difference if tbMaterials value matches a value in the range or not. For Ref_Appliance I'm using the following.
Code:
=OFFSET(Inventory!$B$4,,,COUNTA(Inventory!$B:$B),1)
The code I'm trying to use for validation is as follows.
Code:
Private Sub btAdd_Click()
Dim k As Integer, i As Integer
Dim Ref_Appliance As Range
Dim bMatch As Boolean
For Each Ref_Appliance In Range("B2:B50")
If Ref_Appliance.Value = tbMaterial.Value And tbCost <> "" Then
MsgBox "HEY! No need for price, I got your back pal."
tbCost = ""
End If
If Appliance.Value = tbMaterial.Value And tbQty = "" Then
MsgBox "Hey lazy hows about givin' me a quantity."
tbQty.SetFocus
Exit Sub
End If
If Appliance.Value <> tbMaterial.Value And tbCost <> "" And tbQty = "" Then
MsgBox "Ben you dummy, enter a quantity for your materials."
tbQty.SetFocus
Exit Sub
End If
If Appliance.Value <> tbMaterial.Value And tbCost = "" And tbQty <> "" Then
MsgBox "Seriously Ben? A quantity without a cost? As if."
tbCost.SetFocus
Exit Sub
End If
Next
Please let me know if you know of a way to tackle my problem.
Thank you for having a look,
John