【发布时间】:2014-11-14 08:42:44
【问题描述】:
我正面临 excel 宏语法的复杂性。 我的工作簿包含几张纸,第一张名为“参考表”。 其他工作表中有一些条目我不希望用户通过他们当前正在处理的工作表进行编辑,而只能通过参考工作表进行编辑。
我锁定了单元格并使用了保护表,但是我希望用户在双击相关范围内的一个单元格时收到提示消息,询问他们是否要更改选定的单元格,但在参考工作表。
我的目标是在当前工作表中选择相同的单元格,在参考工作表中选择相同的单元格以便能够对其进行编辑。
我在相应的工作表 VB 中发布了以下代码,但显然最后的 Cells 属性有错误 -> Cells(val1, val2).Select
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("C2:C5,E2")) Is Nothing Then
Else
Dim Msg As String, Title As String
Dim Config As Integer, Ans As Integer
Msg = "Do not modify this entry from the current sheet."
Msg = Msg & vbNewLine
Msg = Msg & "This modification is only enabled in the Reference Sheet."
Msg = Msg & vbNewLine
Msg = Msg & "Would you like to go to the corresponding cell and modify it?"
Title = "Attention"
Config = vbYesNo + vbExclamation
Ans = MsgBox(Msg, Config, Title)
If Ans = vbYes Then
Dim val1 As Integer, val2 As Integer
val1 = ActiveCell.Row
val2 = ActiveCell.Column
Worksheets("Reference Sheet").Activate
Cells(val1, val2).Select
End If
End If
End Sub
非常感谢您的想法。
【问题讨论】: