我有一个包含三列的Excel表格;
当我将标记分配给一个组成员时,我想编写一个宏来自动为组成员分配标记。任何人都可以帮我写一个宏来实现这个任务吗?
答案 0 :(得分:0)
请注意,将此代码写入适当的Sheet模块。
并修改以下常数:
Sheet1:工作表名称
表1:表名
Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveSheet.Name = "Sheet1" Then
Application.ScreenUpdating = False
' Application.EnableEvents = False
Dim PS2 As Boolean 'sheet Protection Situation
Dim i As Integer
PS2 = Sheets("Sheet1").ProtectContents
If Target.Column = [table1[Group Assignment Marks]].Column Then
For i = 1 To ListObjects("Table1").DataBodyRange.Rows.Count
If Target.Row <> i + Range("Table1[#Headers]").Row Then
If [table1].Cells(i, [table1[Student Name]].Column).Value = [table1].Cells(Target.Row - Range("Table1[#Headers]").Row, [table1[Student Name]].Column).Value Then
[table1].Cells(i, [table1[Group Assignment Marks]].Column).Value = Target.Value
End If
End If
Next i
End If
If PS2 Then Sheets("Sheet1").Unprotect
' Application.EnableEvents = True
End If
End Sub