基本上,我想要做的是:
每当我在 B 列插入值时,它都会将该值添加到 A 列,然后将 B 列设置为 0。
A B
23 0
我尝试了这个函数(将 A 作为 uni 传递,将 B 作为 new_value 传递),但它不起作用......
Function foo(uni, new_value)
uni = uni + new_value
End Function
答案1
好的。下面是操作方法,但是没有测试过,因为我懒得加载 Excel。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed. Edit as needed.
Set KeyCells = Range("B2:B10")
If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
' This code is only ran when one of the above cells change
cells(Target.Row, 1).value = cells(Target.Row, 2).value
cells(Target.Row, 2).value = ""
End If
End Sub