【发布时间】:2014-03-26 21:24:03
【问题描述】:
我需要在 EXCEL 2012 VBA 的列中找到最大值。 有些单元格有“#VALUE!”。我的代码不起作用。
Sub find_max()
Dim rng As Range
Dim dblMax As Double
dblMax = 0
Set rng = Range("A2:A11")
For Each cell In rng
If (cell.Value <> "#VALUE!") Then // error ! type mismatch
If dblMax < CDbl(cell.Value) Then
dblMax = CDbl(cell.Value)
End If
End If
Next cell
MsgBox dblMax
End Sub
我还需要用最大值打印单元格位置(用颜色标记)。
任何帮助将不胜感激。
【问题讨论】:
-
将
If (cell.Value <> "#VALUE!") Then更改为If NOT ISERROR(cell) Then -
我还需要打印具有最大值的单元格位置。谢谢!
标签: excel windows-7 excel-2010 vba