excel - 更改时将单元格复制到另一列
问题描述
我需要在更改时将特定列中单元格的内容复制到另一个相应的列,以便移动旧值。只想为特定列工作。
Private sub Worksheet_Change(ByVal Target As Range)
if Target.Range("L:L") then
'set I cell value = to original L cell value
ActiveCell.Offset(0,-3).Value = ActiveCell.Value
End If
End Sub
解决方案
这段代码应该做你想做的事。请注意评论,这些评论解释了我对该程序的操作施加的一些限制。遵循的规则是不要给它比它完成你想要它做的工作所需的更多的权力。
Private Sub Worksheet_Change(ByVal Target As Range)
' 027
Dim Rng As Range
' don't react if the changed cell is in row 1 or
' if it is more than 1 row below the end of column L
Set Rng = Range(Cells(2, "L"), Cells(Rows.Count, "L").End(xlUp).Offset(1))
If Not Application.Intersect(Target, Rng) Is Nothing Then
With Target
' skip if more than 1 cell was changed
' meaning, exclude paste actions
If .Cells.CountLarge = 1 Then
.Offset(0, -3).Value = .Value
End If
End With
End If
End Sub
推荐阅读
- javascript - 反应 getTimezoneOffset 差异
- javascript - JS fn optional-parameter(s) given 'undefined' (to get default) failed for built-ins at least 'new Date(yr,moi,d,hr,min,s,ms)' +Array.prototype.splice
- python - Dash 应用回调似乎没有返回任何内容
- php - 我如何在日历 php 上禁用两天后
- android - 如何在 Android 中通过 SQLiteDatabase 删除所有数据
- python - Binance API 没有响应证书对“api.binance.com”无效
- python - 如何在熊猫中按顺序填充缺失的数据?
- typescript - 如何定义 react-native v5 的嵌套导航道具?
- reactjs - 如何在 URL 中反应应用程序始终打开附加“/”
- azure-iot-hub - 有没有办法将 Azure IOT 中心中存在的数据连接到 IOT Central 智能电表应用程序