Excel détecte si une formule est incompatible avec une colonne calculée dans une table et les montre avec un petit sortingangle vert (qui indique «Cette cellule est incompatible avec la formule de la colonne»). Comment puis-je les find via VBA? J'ai trouvé ce code qui est censé faire le truc (à partir de http://www.ozgrid.com/forum/showthread.php?t=145306 ), mais cela ne fonctionne que lorsque la plage utilisée est une plage normale au lieu d'une table:
Dim oneCell As Range For Each oneCell In ActiveSheet.UsedRange If oneCell.Errors(xlInconsistentFormula).Value Then oneCell.Interior.ColorIndex = 6 Else oneCell.Interior.ColorIndex = xlNone End If Next oneCell
Mais oneCell.Errors(xlInconsistentFormula).Value
n'envoie que "False" pour qu'il ne fonctionne pas.
Est-ce que cela peut être réglé pour fonctionner dans une table au lieu d'une gamme normale?
Edit: xlInconsistentFormula ne fait rien si vous travaillez dans une table.
Cela marche:
Sub fhdjksjdfhs() Dim r As Range Dim rBig As Range Set rBig = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeFormulas) For Each r In rBig If r.Errors.Item(xlInconsistentFormula).Value = True Then r.Interior.ColorIndex = 6 Else r.Interior.ColorIndex = xlNone End If Next r End Sub
Subfhdjksjdfhs ()Sub fhdjksjdfhs() Dim r As Range Dim rBig As Range Set rBig = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeFormulas) For Each r In rBig If r.Errors.Item(xlInconsistentFormula).Value = True Then r.Interior.ColorIndex = 6 Else r.Interior.ColorIndex = xlNone End If Next r End Sub
Dim r As RangeSub fhdjksjdfhs() Dim r As Range Dim rBig As Range Set rBig = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeFormulas) For Each r In rBig If r.Errors.Item(xlInconsistentFormula).Value = True Then r.Interior.ColorIndex = 6 Else r.Interior.ColorIndex = xlNone End If Next r End Sub
Dim rBig As RangeSub fhdjksjdfhs() Dim r As Range Dim rBig As Range Set rBig = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeFormulas) For Each r In rBig If r.Errors.Item(xlInconsistentFormula).Value = True Then r.Interior.ColorIndex = 6 Else r.Interior.ColorIndex = xlNone End If Next r End Sub
Définissez rBig = ActiveSheet.UsedRange.Cells.SpecialCells (xlCellTypeFormulas)Sub fhdjksjdfhs() Dim r As Range Dim rBig As Range Set rBig = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeFormulas) For Each r In rBig If r.Errors.Item(xlInconsistentFormula).Value = True Then r.Interior.ColorIndex = 6 Else r.Interior.ColorIndex = xlNone End If Next r End Sub
Pour chaque r In rBigSub fhdjksjdfhs() Dim r As Range Dim rBig As Range Set rBig = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeFormulas) For Each r In rBig If r.Errors.Item(xlInconsistentFormula).Value = True Then r.Interior.ColorIndex = 6 Else r.Interior.ColorIndex = xlNone End If Next r End Sub
Si r.Errors.Item (xlInconsistentFormula) .Value = True ThenSub fhdjksjdfhs() Dim r As Range Dim rBig As Range Set rBig = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeFormulas) For Each r In rBig If r.Errors.Item(xlInconsistentFormula).Value = True Then r.Interior.ColorIndex = 6 Else r.Interior.ColorIndex = xlNone End If Next r End Sub
r.Interior.ColorIndex = 6Sub fhdjksjdfhs() Dim r As Range Dim rBig As Range Set rBig = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeFormulas) For Each r In rBig If r.Errors.Item(xlInconsistentFormula).Value = True Then r.Interior.ColorIndex = 6 Else r.Interior.ColorIndex = xlNone End If Next r End Sub
r.Interior.ColorIndex = xlNoneSub fhdjksjdfhs() Dim r As Range Dim rBig As Range Set rBig = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeFormulas) For Each r In rBig If r.Errors.Item(xlInconsistentFormula).Value = True Then r.Interior.ColorIndex = 6 Else r.Interior.ColorIndex = xlNone End If Next r End Sub
Next rSub fhdjksjdfhs() Dim r As Range Dim rBig As Range Set rBig = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeFormulas) For Each r In rBig If r.Errors.Item(xlInconsistentFormula).Value = True Then r.Interior.ColorIndex = 6 Else r.Interior.ColorIndex = xlNone End If Next r End Sub
EDIT # 1:
Comme Kersijus l'indique correctement, la conversion d'une colonne ou d'un set de colonnes en Table supprime le niveau de vérification des erreurs qui soulève le drapeau vert. Ce code ne détectera pas les erreurs qui sont supprimées de cette façon.
Si vous avez une formule incompatible, vous devriez voir quelque chose comme ceci:
Si vous n'en avez rien, vous pourriez avoir des notifications désactivées (je pense que c'est possible).