更新时间:2023-02-01 09:35:53
假定您使用了间接引用( TeamA
下的行被命名为 TeamA
等):
Assuming you used indirect referencing (the rows under TeamA
are named TeamA
and so on):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng(1) As Range, rng1 As Range
Set rng(0) = Range("E1") 'your primary selection
Set rng(1) = Range("F1:H1") 'your secondary selection range
Application.EnableEvents = False
If Not Intersect(Target, rng(0)) Is Nothing Then 'if you have changed your primary selection
For Each rng1 In rng(1) 'each cell in your secondary selection
i = i + 1
rng1 = Range("" & rng(0).Value2)(i, 1) 'gets changed to the nth value in the indirect reference of the primary selection ("TeamA" 's second row is "MemberA2" for example)
Next
End If
Application.EnableEvents = True
End Sub
您需要将此子项放入工作表模块中,并以 .xlsm
扩展名保存文件.
You need to place this sub into your worksheet module and save the file with .xlsm
extension.