我對VBA相當陌生。基本上,我的代碼試圖根據區域列中的最大值輸出分類,該列有幾個類別。邏輯似乎是正確的,但我繼續獲得#VALUE!錯誤。任何幫助將非常感激!VBA值錯誤
Public Function luclass(NAPS As Double) As String
Dim lastrow As Long
Dim c As Range, rng As Range
Dim maxclass As String
Dim maxshape As Double
With ThisWorkbook.Worksheets("LandUseClass2")
lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
maxclass = "Blank"
maxshape = 0
For Each c In .Range("B2:B650" & lastrow)
If c.Value = NAPS Then
If .Range("F" & c.Row).Value > maxshape Then
.Range("C" & c.Row).Text = maxclass
End If
End If
Next c
End With
luclass = maxclass
End Function
怎麼叫這個功能呢?如果它是由單元格公式調用的用戶定義函數(UDF),則不能這樣做。函數接受輸入,計算東西,併產生輸出 - 沒有副作用:函數不能修改其他單元格。 –