Excel 在另一个工作表中选择当前活动的单元格

Excel 在另一个工作表中选择当前活动的单元格,excel,vba,Excel,Vba,我面临excel宏语法的复杂性。 我的工作簿包含几张工作表,第一张题为“参考工作表”。 其他工作表中有一些条目,我不希望用户通过他们当前正在处理的工作表进行编辑,但只能通过参考工作表进行编辑 我锁定了单元格并使用了“保护表”,但我希望用户在双击相关区域中的一个单元格时收到提示消息,询问他们是否要更改参考表中的选定单元格 我的目标是在当前工作表中选择相同的单元格,在参考工作表中选择相同的单元格,以便能够对其进行编辑 我在相应的工作表VB中发布了以下代码,但显然在末尾的Cells属性->Cells(

我面临excel宏语法的复杂性。 我的工作簿包含几张工作表,第一张题为“参考工作表”。 其他工作表中有一些条目,我不希望用户通过他们当前正在处理的工作表进行编辑,但只能通过参考工作表进行编辑

我锁定了单元格并使用了“保护表”,但我希望用户在双击相关区域中的一个单元格时收到提示消息,询问他们是否要更改参考表中的选定单元格

我的目标是在当前工作表中选择相同的单元格,在参考工作表中选择相同的单元格,以便能够对其进行编辑

我在相应的工作表VB中发布了以下代码,但显然在末尾的Cells属性->Cells(val1,val2)中有一个错误。选择

非常感谢您的想法。

代码失败的原因是在
工作表
模块中,非限定范围引用(
单元格(val1,val2)
在您的情况下)指的是工作表模块,而不是活动工作表。由于您刚刚激活了另一张工作表,因此您正在尝试选择非活动工作表上的单元格,这会导致错误

更好的方法是

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 Long, Ans As VbMsgBoxResult

        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
            With Worksheets("Reference Sheet")
                .Activate
                .Range(Target.Address).Select
            End With

        End If
    End If
End Sub

谢谢你抽出时间来解决我的问题。
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 Long, Ans As VbMsgBoxResult

        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
            With Worksheets("Reference Sheet")
                .Activate
                .Range(Target.Address).Select
            End With

        End If
    End If
End Sub