0

I need help on how to use checkbox array , if checkbox is checked the value will be:

check1(0) = OK ,check1(1) = X,check1(2) = [X],check1(3) = NP
a=iif(check1(0).Value = vbchecked,"OK")

Getting error:

"Error sub or function not defined"
3
  • Are you sure you want to use iif and not if. See help. If check1(0).Value = vbchecked then A = "OK". Commented Mar 2, 2020 at 2:36
  • I have 4 checkboxes if I check(0) then the value will be ok and if i check(1) the value will X. Commented Mar 2, 2020 at 3:31
  • Your IIf is missing an argument. Commented Mar 2, 2020 at 12:12

1 Answer 1

1

I'm not sure how the line of code you presented would generate the error sub or function not defined. Rather, you should have received the errorArgument not optional. The syntax for this line should have been like this:

a = IIf(Check1(0).Value = vbChecked, "OK", "")

If I understand your requirements, you COULD use IIf like this:

a = IIf(Check1(0).Value = vbChecked, "OK", IIf(Check1(1).Value = vbChecked, "X", IIf(Check1(2).Value = vbChecked, "[X]", IIf(Check1(3).Value = vbChecked, "NP", ""))))

However, I would not recommend this approach. Instead, I would structure the code like this:

If Check1(0).Value = vbChecked Then
   a = "OK"
ElseIf Check1(1).Value = vbChecked Then
   a = "X"
ElseIf Check1(2).Value = vbChecked Then
   a = "[X]"
ElseIf Check1(3).Value = vbChecked Then
   a = "NP"
Else
   a = ""
End If

Yes, there is a little more code but the code is easier to read and easier to maintain.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.