我有1-100行。 我知道如何定位特定的单元格并从中获取数据,但是当可以更改从1到100的任何行时,我该怎么做?
假设您将任何东西放入A3行。您如何通过VBA将“已更新”写入B3行? 我希望这适用于A1-A100行。
谢谢
答案 0 :(得分:2)
在工作表代码区域中放置以下事件宏:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, Intersection As Range, Cell As Range
Set A = Range("A1:A100")
Set Intersection = Intersect(Target, A)
If Intersection Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each Cell In Intersection
Cell.Offset(0, 1).Value = "Updated"
Next Cell
Application.EnableEvents = True
End Sub
答案 1 :(得分:1)
粘贴代码
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
With ThisWorkbook.Worksheets("Sheet1")
If Not Intersect(Target, .Range("A1:A100")) Is Nothing Then
Application.EnableEvents = False
.Range("B" & Target.Row).Value = "Updated"
Application.EnableEvents = True
End If
End With
End Sub