PDA

View Full Version : I get the error with that if condition.



alex009988
08-25-2019, 10:18 AM
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"?

Bob Phillips
08-25-2019, 12:10 PM
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