Comment find des cellules avec "#VALUE!" dans EXCEL 2010 VBA

Je dois find la valeur maximale dans une colonne par EXCEL 2012 VBA. Certaines cellules ont "#VALUE!". Mon code ne fonctionne pas.

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 

J'ai également besoin d'imprimer l'location de la cellule (le marquer avec une couleur) avec la valeur maximale.

Toute aide serait appréciée.

Si votre gamme a des constantes, utilisez

 application.WorksheetFunction.Max(range("B6:C13").SpecialCells(xlcelltypeconstants,xlNumbers )) 

s'il a des formules, utilisez

 application.WorksheetFunction.Max(range("B6:C13").SpecialCells(xlcelltypeformulas,xlNumbers )) 

Pour la gamme où il se trouve, .Find devrait fonctionner .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