如何查找带有“的单元格”#价值&引用;在Excel2010VBA中
我需要通过EXCEL 2012 VBA在列中查找最大值。 有些单元格有“#值!”。我的代码不起作用如何查找带有“的单元格”#价值&引用;在Excel2010VBA中,excel,windows-7,excel-2010,vba,Excel,Windows 7,Excel 2010,Vba,我需要通过EXCEL 2012 VBA在列中查找最大值。 有些单元格有“#值!”。我的代码不起作用 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
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
Sub find_max()
变暗rng As范围
Dim dblMax为双精度
dblMax=0
设置rng=范围(“A2:A11”)
对于rng中的每个单元
如果(cell.Value“#Value!”),则//错误!类型不匹配
如果dblMax
我还需要用最大值打印单元格位置(用颜色标记)
任何帮助都将不胜感激 如果您的范围有常数,请使用
application.WorksheetFunction.Max(range("B6:C13").SpecialCells(xlcelltypeconstants,xlNumbers ))
如果有公式,请使用
application.WorksheetFunction.Max(range("B6:C13").SpecialCells(xlcelltypeformulas,xlNumbers ))
对于找到它的范围,.Find
应该可以正常工作:
Sub find_max()
Dim rng As Range
Dim dblMax As Double, rgMax As Range
Set rng = Range("A2:A11")
dblMax = Application.WorksheetFunction.Max(rng.SpecialCells(xlCellTypeFormulas, xlNumbers))
Set rgMax = rng.Find(dblMax, , xlValues, xlWhole)
MsgBox rgMax.Address & ": " & dblMax
End Sub
将
If(cell.Value“#Value!”)更改为如果不是iError(cell),则
我还需要使用最大值打印单元格位置。谢谢我在dblMax=Application.WorksheetFunction.Max(rng.SpecialCells(xlCellTypeFormulas,xlNumbers)处出错。谢谢如果您的所有数字都是常量,请将该行与Application.WorksheetFunction.Max(范围(“B6:C13”).SpecialCells(xlcelltypeconstants,xlNumbers))