I have a userform with many textboxes (describe paramenter of tests). I want to use function in order to check each textbox if it's value is in specific range. Allowed values ranges are appearing in excel sheet "T_list) - for each parameter there is different range.If the value of textbox is in the range, the function will return "true", otherwise it will return "false".
Here is how i call to this function:
g = CheckGreen(Test_Procedure, CWS1, 1)
msgbox(g)
Test_Procedure- name of userform, CWS1 - name of specific textbox, 1 - the first range of value (in the table in the eacel sheet T_list)
Here is the code of the function which doesn't work, since the txtbox argument is get the value of the cell and not the taxtbox name. what i'm doing wrong?
Public Function CheckGreen(formName As UserForm, txtbox As MSForms.TextBox, i As Integer) As Boolean
If formName.txtbox.Value >= Sheets("T_list").Range("T_Start").Offset(i, 0).Value And formName.txtbox.Value <= Sheets("T_list").Range("T_Start").Offset(i, 1).Value Then
formName.txtbox.BackColor = &HFF00& ' Green
Sheets("Test_Data").Range("D_Start").Offset(T_R, 8).Value = formName.txtbox.Value
CheckGreen = True
Else
formName.txtbox.BackColor = &H3535FD ' Red
Sheets("Test_Data").Range("D_Start").Offset(T_R, 8).Value = formName.txtbox.Value
CheckGreen = False
End If
End Function
*****edited according to @Banana comment:
this is my function code using the string option (per @Banana comment):
Public Function CheckGreen1(formName As UserForm, txtbox As String, i As Integer) As Boolean
If formName.Controls(txtbox).Value >= Sheets("T_list").Range("T_Start").Offset(i, 0).Value And formName.Controls(txtbox).Value <= Sheets("T_list").Range("T_Start").Offset(i, 1).Value Then
formName.Controls(txtbox).BackColor = &HFF00& ' Green
Sheets("Test_Data").Range("D_Start").Offset(T_R, 8).Value = formName.Controls(txtbox).Value
CheckGreen1 = True
Else
formName.Controls(txtbox).BackColor = &H3535FD ' Red
Sheets("Test_Data").Range("D_Start").Offset(T_R, 8).Value = formName.Controls(txtbox).Value
CheckGreen1 = False
End If
End Function
Here is how i call the function:
g = CheckGreen(CWS1.Value, 1, CWS1)
This option is still doesn't work sinse the value now is string, and the IF equation doesn't recognize the value as number, and go alwayse to 'False' (even if the value is in the allowed range).
Please your assistance, thanks
"CWS1", and you use it as described in the link from my first comment.