VBA值错误
我对VBA相当陌生。 基本上,我的代码尝试输出一个区域列中的最大值的分类,它有几个类别。 逻辑似乎是正确的,但我继续获得#VALUE! 错误。 任何帮助将非常感激!
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
- 将
.Range("B2:B650" & lastrow)
更改为.Range("B2:B" & lastrow)
- 将
.Range("C" & c.Row).Text = maxclass
改为.Range("C" & c.Row).Value = maxclass
as.text
是一个只读属性。
您正在获取#Value
错误,因为您正在尝试写入函数中的范围。
使用Sub
而不是Function
解释你到底想要达到什么目标,我们将会把它变成:)
Public Sub luclass(NAPS As Double)