Consulting

Results 1 to 2 of 2

Thread: I get the error with that if condition.

  1. #1

    I get the error with that if condition.

    Hello.
    I have some problem in the userform. In order to not represent whole userform code, I represented that problem "invalid procedure call" in a small macros.
    Here we go
    Sub test()
    Dim hhh, n, c, s1, nr(), g5
    hhh = "yes1"
    n = 10
    c = 5
    s1 = 15
    Select Case hhh
    Case "no"
    Case "yes"
        For h = 1 To s1
    ReDim Preserve nr(1 To s1)
    nr(h) = n - c
    Next h
    End Select
       If Not IsEmpty(nr) Then
        g5 = Application.Average(nr)
        Debug.Print Join(nr, " ")
        Debug.Print g5
        End If
    End Sub
    The problem is that if nr is empty it nevertheless calculates g5 and I got the error on that line.
    How to stop the calcalation of if condition of g5 in case of hhh="something" not "yes"?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    25,082
    Location
    How about this

    Sub test()
    Dim hhh, n, c, s1, nr(), g5, h
    
        hhh = "yes1"
        n = 10
        c = 5
        s1 = 15
        
        Select Case hhh
            Case "no"
            Case "yes"
                For h = 1 To s1
                    ReDim Preserve nr(1 To s1)
                    nr(h) = n - c
                Next h
        End Select
        
        If Not Not nr Then
        
            g5 = Application.Average(nr)
            Debug.Print Join(nr, " ")
            Debug.Print g5
        End If
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •