Worksheet イベント (Excel)Worksheet.Change event (Excel)
ワークシートのセルがユーザーまたは外部リンクにより変更されたときに発生します。Occurs when cells on the worksheet are changed by the user or by an external link.
構文Syntax
式。変更(ターゲット)expression.Change (Target)
式Worksheet オブジェクトを表す変数を取得します。expression A variable that represents a Worksheet object.
パラメーターParameters
名前Name | 必須 / オプションRequired/Optional | データ型Data type | 説明Description |
---|---|---|---|
TargetTarget | 必須Required | RangeRange | 変更された範囲が渡されます。The changed range. 複数のセルを渡すことができます。Can be more than one cell. |
戻り値Return value
NothingNothing
注釈Remarks
セルが再計算時に変更されると、このイベントは発生しません。This event does not occur when cells change during a recalculation. 計算 イベントを使用して、シートの再計算をトラップします。Use the Calculate event to trap a sheet recalculation.
例Example
次のコード例は、変更されたセルの色を青色にします。The following code example changes the color of changed cells to blue.
Private Sub Worksheet_Change(ByVal Target as Range)
Target.Font.ColorIndex = 5
End Sub
次のコード例は、セル値が変更されたときに、変更されたセルが列 A 内にあることを確認すると共に、変更されたセル値が 100 よりも大きいかどうかを確認します。The following code example verifies that, when a cell value changes, the changed cell is in column A, and if the changed value of the cell is greater than 100. 値が 100 よりも大きい場合、列 B 内の隣接するセルの色が赤に変更されます。If the value is greater than 100, the adjacent cell in column B is changed to the color red.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column = 1 Then
ThisRow = Target.Row
If Target.Value > 100 Then
Range("B" & ThisRow).Interior.ColorIndex = 3
Else
Range("B" & ThisRow).Interior.ColorIndex = xlColorIndexNone
End If
End If
End Sub
次のコード例は、データがセルに入力された場合に、セル範囲 A1:A10 内の値を大文字に設定します。The following code example sets the values in the range A1:A10 to be uppercase as the data is entered into the cell.
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1:A10")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
'Set the values to be uppercase
Target.Value = UCase(Target.Value)
Application.EnableEvents = True
End Sub
サポートとフィードバックSupport and feedback
Office VBA またはこの説明書に関するご質問やフィードバックがありますか?Have questions or feedback about Office VBA or this documentation? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.