ビデオポストプロダクションで行われたすべての作業の効率を高めるためにマクロを構築するための情報を狩りと掘り出していることから、あなたのVBAに関する知識は限られていて、関連性がある。この回答は、私が必要としていると信じているイベントルーチンの紹介です。
イベントが発生しました:ブックのオープンまたはクローズ、ワークシートの追加、セル値の変更などこれらのイベントの多くは、そのイベントが発生したときに呼び出されるルーチンを作成できます。
これらのルーチンを示すために、ワークブックと「ワーク」ワークシートを作成しました。 12個のセルを数値に設定し、R12をその合計に設定しました。私は範囲J2:O25を1から144の数字に設定しました。これはあなたが望むよりも広い範囲ですが、これは原理には何の影響もありません。
以下のコードでは、私はWorkbook_Open
とWorkbook_SheetChange
という2つのイベントルーチンを使用しています。
Workbook_Open
には、私はR12の元の値を保存します。 Workbook_SheetChange
では、R12の値が変更され、J2:O25に新しい値が含まれている場合は、その値にカーソルを移動します。
私があなたの質問を理解していれば、これはあなたが求めている機能です。もしそうでなければ、私はこの答えがより良い、より詳細な質問をするのに役立つことを願っています。
あなたは、モジュール内のこのステートメントを配置する必要があります:
Public R12Last As Variant
はあなたがシーツの下にMicrosoft Excel Objects
で見つけるThisWorkbook
に次のコードを配置する必要があります。
Option Explicit
Sub Workbook_Open()
' This routine is called when the workbook is opened.
With Worksheets("Work")
' Save the value of cell R12 when the workbook opens.
R12Last = .Range("R12").Value
End With
End Sub
Private Sub Workbook_SheetChange(ByVal WSht As Object, ByVal ChgRng As Range)
' This routine is called when cells in any worksheet are changed by the
' user or by an external link.
' WSht is the worksheet within which cells have changed.
' ChgRng can be a single cell or a range.
' For this application, we are not interested in the cell that has changed.
' We want to know if the change affected R12.
Dim SearchRng As Range
Dim FoundRng As Range
With Worksheets("Work")
If R12Last <> .Range("R12").Value Then
' Cell R12 has changed
R12Last = .Range("R12").Value ' Record the new value for next time
' I have a larger range containing the values that might be in R12
' but the principle is the same. You will need to change this to M31:M40.
Set SearchRng = .Range("J2:O25")
' Look for the new value of R12 in SearchRng.
' "What" is the value to be found. "After" must be within the search
' range. "After" is the last cell to be searched. I have set
' SearchDirection to xlNext and SearchOrder to xlByRows so the Find will
' check cells starting with J2.
' Look Find up in VBA Help for a fuller description.
Set FoundRng = SearchRng.Find(What:=R12Last, After:=Range("O25"), _
LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext)
If FoundRng Is Nothing Then
' The value of R12 has not been found in the search range.
' Add code to handle this situation
Call MsgBox("Target value not found", vbOKOnly)
Else
' Make the cell with the matching value the active cell.
FoundRng.Select
End If
End If
End With
End Sub
?誰かが値を入力すると、いくつかの 'VBA'がこれを行うことができます。 –
あなたはこれの大きな目的についていくつかの光を放つことができますか?たぶんあなたの全体的なアプローチも助けを必要とするかもしれません。 – Marc
Activecellアドレスは、ルーチンの最初に格納することができます。コードを投稿することを検討する必要があります。これまで説明したことから、必要以上に難しいものになっているように思えます。 –