ヒント:他の言語はGoogle翻訳されています。 訪問することができます English このリンクのバージョン。
ログイン
x
or
x
x
お申し込み
x

or

Excelでセルが変更された回数を数えるには?

Excelでセルが変更された回数をカウントするには、この記事を参考にしてください。

VBAコードでセルが変更された回数をカウントする


VBAコードでセルが変更された回数をカウントする


Excelでセルが変更された回数をカウントするには、次のようにしてください。

1。 ワークシートで、指定したセルの合計変更を数え、シートタブを右クリックしてから、をクリックします。 コードを表示 コンテキストメニューから選択します。 スクリーンショットを見る:

2。 オープニング アプリケーション用Microsoft Visual Basic VBAコードの下にコピーしてコードウィンドウに貼り付けてください。

VBAコード:Excelでセルが変更された回数

Dim xCount As Integer

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xRg As Range, xCell As Range
    On Error Resume Next
    If Target = Range("B9") Then
        xCount = xCount + 1
        Range("C9").Value = xCount                                     
    End If
    Application.EnableEvents = False
    Set xRg = Application.Intersect(Target.Dependents, Me.Range("B9"))
    If Not xRg Is Nothing Then
        xCount = xCount + 1
        Range("C9").Value = xCount
    End If
    Application.EnableEvents = True
End Sub

:コードでは、B9は変更をカウントするために必要なセルで、C9はカウント結果を取り込むセルです。 必要に応じて変更してください。

これ以降、B9セルで変更が行われると、その変更の合計数が重複してC9セルに自動的に設定されます。



Excelの推奨生産性向上ツール

Kutools for Excelを使用すると、いつでも作業を終わらせることができ、群衆から目立つようにすることができます。

  • 300作業シナリオ用に設計された1500以上の強力な高度な機能により、生産性を70%向上させ、家族の世話をしたり人生を楽しんだりするための時間を増やすことができます。
  • 数式やVBAコードを暗記する必要はもうありません。これから脳を休ませてください。
  • 3分でExcelのエキスパートになる、複雑で繰り返しのある操作が数秒で可能
  • 毎日何千ものキーボードとマウスの操作を減らし、今や職業病に別れを告げる。
  • 110,000の非常に効果的な人々と300 +世界的に有名な企業の選択。
  • 60-dayフル機能無料トライアル。 60日の返金保証。 2年間の無料アップグレードとサポート。

ブラウザのタブよりはるかに強力な、タブ付きのブラウジングと編集をMicrosoft Officeにもたらします。

  • Officeタブは、Word、Excel、PowerPoint、およびその他のOfficeアプリケーション(発行元、アクセス、Visio、およびプロジェクト)用に設計されています。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を50%向上させ、毎日数百回のマウスクリックを削減します。
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    JediTrader · 2 months ago
    Team,

    When I tried using :

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xRg As Range, xCell As Range
    Dim xSRg, xRRg As Range
    Dim xFNum As Long

    Set xSRg = Range("B9:B1000")
    Set xRRg = Range("C9:C1000")

    carefully changing the Range and Target cells vis a vis P2:P200 and X2:X200 respectively, I dont the change-count in X Column despite myself trying to change cells across multiple rows across P2:P200.

    Any help would be greatly appreciated.

    Regards
    JT
  • To post as a guest, your comment is unpublished.
    Shiju · 4 months ago
    Hello All,

    The solution as provided under "Count Number Of Times A Cell Is Changed With VBA Code" is good if we are only tracking changes to ONE CELL. Please suggest, what modifications are needed, if the tracking is to be done for multiple cells. In case of multiple cells, the incremental counter should appear next to the cell for which the change in value is being tracked.
    • To post as a guest, your comment is unpublished.
      Shiju · 4 months ago
      Looking forward for help and assistance to have a specific VBA code, which can be applied to multiple cells in one worksheet.
      • To post as a guest, your comment is unpublished.
        crystal · 4 months ago
        Hi Shiju,
        Please try the below VBA code. Thanks for commenting.

        Private Sub Worksheet_Change(ByVal Target As Range)
        Dim xRg As Range, xCell As Range
        Dim xSRg, xRRg As Range
        Dim xFNum As Long

        Set xSRg = Range("B9:B1000")
        Set xRRg = Range("C9:C1000")

        Application.EnableEvents = False
        On Error Resume Next
        For xFNum = 1 To xSRg.count
        If Target = xSRg.Item(xFNum) Then
        xRRg.Item(xFNum).Value = xRRg.Item(xFNum).Value + 1
        Application.EnableEvents = True
        Exit Sub
        End If
        Next xFNum
        Application.EnableEvents = True
        End Sub
  • To post as a guest, your comment is unpublished.
    Kevin · 1 years ago
    Did you figure this out. I too am interested in this for checking multiple cells. Haven’t tried it yet.
    • To post as a guest, your comment is unpublished.
      crystal · 11 months ago
      Hi Kevin,

      The following code can help you solving the problem. Thanks for your comment.
      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRg As Range, xCell As Range
      Dim xSRg, xRRg As Range
      Dim xFNum As Long

      Set xSRg = Range("B9:B1000")
      Set xRRg = Range("C9:C1000")

      Application.EnableEvents = False
      On Error Resume Next
      For xFNum = 1 To xSRg.count
      If Target = xSRg.Item(xFNum) Then
      xRRg.Item(xFNum).Value = xRRg.Item(xFNum).Value + 1
      Application.EnableEvents = True
      Exit Sub
      End If
      Next xFNum
      Application.EnableEvents = True
      End Sub
  • To post as a guest, your comment is unpublished.
    Jan · 1 years ago
    Thank you very much ! This works great.

    But how do you get the same function/rule to work for a range of cells, along an entire column, for example?

    I have a list of my business' contacts on different rows, with their contact details in different columns, and I want a add a column that registers and counts the number of times a given cell along each row is changed. The code you gave works great, but only for one cell at a time !

    I'm new to VBA, so I would greatly appreciate your support.

    I tried adding a range of cells into the code, so instead of "B9" and "C9", as given in the example above, I played around with variations like "B:B", "C:C", or "B9:B1000" and "C9:C1000", without any success.

    Thanks in advance,
    • To post as a guest, your comment is unpublished.
      crystal · 11 months ago
      Hi Jan,
      Please try the below VBA code. Hope it can help. Thanks for your comment.

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRg As Range, xCell As Range
      Dim xSRg, xRRg As Range
      Dim xFNum As Long

      Set xSRg = Range("B9:B1000")
      Set xRRg = Range("C9:C1000")

      Application.EnableEvents = False
      On Error Resume Next
      For xFNum = 1 To xSRg.count
      If Target = xSRg.Item(xFNum) Then
      xRRg.Item(xFNum).Value = xRRg.Item(xFNum).Value + 1
      Application.EnableEvents = True
      Exit Sub
      End If
      Next xFNum
      Application.EnableEvents = True
      End Sub
      • To post as a guest, your comment is unpublished.
        Jonathan · 10 months ago
        Hi Crystal,

        This is brilliant, on my matrix I have used this on one of the columns but I have struggled to duplicate this across multiple columns. Do you have a solution?

        Thanks in Advance