当我通过下拉列表将第 V 列中的单元格更新为“已售出”或“活动”时 我想将适用单元格的值从 W 列复制并粘贴到 Y 列
原因是因为我在 W 列使用了 XLookUp,该列的价格每天都会波动。 这个想法是能够仅使用 V 列更改为“已售”或“活动”时的值来冻结 Y 列中的价格
我一直在搜索教程、视频和文章,但似乎不太明白。这是我从互联网上获取的最新片段,并试图自己弄清楚。
Sub ReadMarks()
Dim i As Long
' Go through the marks columns
For i = 2 To 11
' Check if marks greater than 50
If Sheet1.Range("C" & i).Value > 50 Then
' Print student name to the Immediate Window(Ctrl + G)
Debug.Print Sheet1.Range("A" & i).Value & " " & Sheet1.Range("B" & i).Value
End If
Next
End Sub
右键单击工作表选项卡 >
View Code
> 将代码插入工作表模块
当用户修改 V 列中的任何单元格时,以下代码会将 W 列的值复制到与更改的单元格同一行的 Y 列。
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .CountLarge = 1 Then
If .Column = 22 And (.Value = "Sold" Or .Value = "Active") Then
Application.EnableEvents = False
Me.Cells(.Row, "Y").Value = Me.Cells(.Row, "W").Value
Application.EnableEvents = True
End If
End If
End With
End Sub