[英]Function return an error #Value! when I try to use it
我想問當我想返回我的 function 的值時出現錯誤的原因是什么
Public Function Alphabet_SEF() As Integer
Dim AllAreAlphabetic As Boolean
Dim ReturnVal As Integer
AllAreAlphabetic = True
Sheets("BlaBla").Activate
For i = 1 To Sheets("BlaBla").Range("E1", Range("E1").End(xlDown)).Rows.Count
If (VarType(Range("E1")) <> 8) Then
AllAreAlphabetic = False
Exit For
End If
Next
Sheets("CdM").Activate
If (AllAreAlphabetic) Then
ReturnVal = 1
Else
ReturnVal = 0
End If
Alphabet_SEF = ReturnVal
End Function
當我放入我的 exel 書時,“=Alphabet_SEF()”出現#value!
試試這個 - 它不依賴 BlaBla 處於活動狀態
Public Function Alphabet_SEF() As Boolean
Dim rng As Range, c As Range
Application.Volatile 'forces recalculation: use when you have no parameters for
' Excel to use to determine when it needs to be recalculated
With Sheets("BlaBla")
Set rng = .Range(.Range("E1"), .Cells(.Rows.Count, "E").End(xlUp))
End With
For Each c In rng.Cells
If VarType(c) <> 8 Then
Alphabet_SEF = False 'set to false and exit function
Exit Function
End If
Next
Alphabet_SEF = True 'if got here then all values are type 8
End Function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.