我有一个共享的主表,可以被多个用户访问。我想使用宏跟踪用户所做的更改,然后保留第一个用户所做的更改,并给其他用户一个msgbox,表示已经进行了更改。现在功能区中的“共享工作簿”选项中有一个选项,上面写着“问我哪个更改获胜”,但我希望第一个用户进行更改而不会弹出任何对话框。我尝试了“将更改保存为胜利”选项,但是它没有按预期方式工作。是否可以使用宏来完成此操作?如果可以,怎么办?
答案 0 :(得分:0)
Private Sub Worksheet_Change(ByVal Target As Range)
Set FindCell = Worksheets("Track Changes").Columns(2).Find(Target.Address, LookIn:=xlValues)
R = Worksheets("Track Changes").Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
If FindCell Is Nothing Then
With Worksheets("Track Changes")
.Cells(R, 1).Value = Date
.Cells(R, 2).Value = Target.Address
.Cells(R, 3).Value = Application.UserName
If Target.Value = "" Then
.Cells(R, 4).Value = "Empty cell"
Else
.Cells(R, 4).Value = Target.Value
End If
End With
Else
firstAddress = FindCell.Address
Do
If FindCell.Offset(0, -1).Value = Date Then
MsgBox "Changes already made by " & FindCell.Offset(0, 1).Value & _
vbNewLine & "Changes: " & FindCell.Offset(0, 2).Value
Exit Sub
End If
Set FindCell = Worksheets("Track Changes").Columns(2).FindNext(FindCell)
Loop While Not FindCell Is Nothing And FindCell.Address <> firstAddress
With Worksheets("Track Changes")
.Cells(R, 1).Value = Date
.Cells(R, 2).Value = Target.Address
.Cells(R, 3).Value = Application.UserName
If Target.Value = "" Then
.Cells(R, 4).Value = "Empty cell"
Else
.Cells(R, 4).Value = Target.Value
End If
End With
End If
End Sub