特定の地域の矛盾した式をチェックすることは可能ですか?
私の場合、列 D と列 E には異なる式のセットが含まれています。
列 E のすべての数式が一貫していることを確認したいだけです。
そうすることは可能ですか??
これが1つの方法です。
ワークシートが次のようになっているとしましょう
このコードをモジュールに貼り付けて実行します。どのセルに一貫性のない数式があるかがわかります。以下のスクリーンショットを参照してください
コードを理解するのに問題がないように、コードにコメントを付けました。あなたが単に尋ねるなら:)
Option Explicit
Sub GetInConsCells()
Dim ws As Worksheet
Dim rng As Range, cl As Range, errCells As Range
Dim ErrorCells As String
Dim lRow As Long
'~~> Create a temp copy of the sheet
ThisWorkbook.Sheets("Sheet1").Copy After:=Sheets(ThisWorkbook.Sheets.Count)
Set ws = ActiveSheet
With ws
'~~> Clear Col D and Col F Contents
.Range("D:D,F:F").ClearContents
'~~> Find the last row of col E
lRow = .Range("E" & .Rows.Count).End(xlUp).Row
'~~> Set your range
Set rng = Range("E1:E" & lRow)
'~~> Check if the cells have inconsistent formulas
For Each cl In rng
If cl.Errors(xlInconsistentFormula).Value Then
If errCells Is Nothing Then
Set errCells = cl
Else
Set errCells = Union(cl, errCells)
End If
End If
Next cl
'~~> Display relevant message
If Not errCells Is Nothing Then
ErrorCells = errCells.Address
MsgBox "Formulas in cells " & ErrorCells & " are inconsitent"
Else
MsgBox "All Formulas are consistent"
End If
End With
'~~> Delete temp sheet
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End Sub
すばやく実用的な方法は、別の列を(一時的に)使用することです。列Eの各セルに数式があることを確認したい場合は、別の列=SUM(A1:D1)
に数式を入力するだけです。=(SUM(A1:D1)-E1
次に、列を選択してフィルターをFALSE
かけます。これにより、結果が異なるすべての数式が得られます。