1

I'm trying to run a function within my Sub but am getting a compile error on the line x = NINOFunction() and am not sure how to get it working.

Sub CheckNINO()
    Dim NINumber As Range, NINumbers As Range
    Dim Usdrws As Long, x As Boolean

    Usdrws = Worksheets("EeeDetails").Range("C" & Rows.Count).End(xlUp).Row
    Set NINumbers = Worksheets("EeeDetails").Range("Q2:Q" & Usdrws)

    For Each NINumber In NINumbers
        x = NINOFunction(NINumber.Value)
        If x = False Then
            Range(NINumber).Copy Destination:=Worksheets("Validation").Cells(2, x)
        End If
    Next
End Sub

Function NINOFunction(sInp As String) As Boolean
    Const s1 As String = "[AaBbCcEeGgHhJjKkLlMmNnOoPpRrSsTtWwXxYyZz]"
    Const s2 As String = "[AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtWwXxYyZz]"
    Const s3 As String = "######"
    Const s4 As String = "[AaBbCcDd]"

    NINO = sInp Like s1 & s2 & s3 & s4
End Function

The function is tested and works with a Boolean result.

If the result is False I want to copy the row across to a separate sheet.

2 Answers 2

2

Your compilation error is "Argument is not optional". This is quite good error message. Thus write x = NINOFunction(arg) and put an argument sInp.

Something like x = NINOFunction ("something")

or probably you need:

x = NINOFunction (NINumber)

Furthermore, your function always returns False, because this is the default value of the Boolean function. You may consider fixing it like this:

Function NINOFunction(sInp As String) As Boolean
    Const s1 As String = "[AaBbCcEeGgHhJjKkLlMmNnOoPpRrSsTtWwXxYyZz]"
    Const s2 As String = "[AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtWwXxYyZz]"
    Const s3 As String = "######"
    Const s4 As String = "[AaBbCcDd]"

    NINOFunction = sInp Like s1 & s2 & s3 & s4
End Function
Sign up to request clarification or add additional context in comments.

4 Comments

Hi Vityata, thanks for the response, I'm still getting a compile error: Argument not optional error though
I was wondering about your original response. The parameter to the NINOFunction function is not optional. edit Your last reponse looks like a call to a procedure; not a function.
@Jeeped - yup true. I have simply started to remove parenthesis everywhere in Subs since the last week, thus this new habit results in flaws like the one above.
Excellent thanks Vityata, I was wondering why they were all returning False, didn't realise I hadn't updated the Variable name at the end!!
0

NINOFunction takes 1 argument, which is a string, but you didn't pass any. Try x = NINOFunction("something")

2 Comments

And, of course, replace "something" with the desired input string.
Thanks Magnetron, I was unaware that I had to assign the function like that, but it makes perfect sense!

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.