在我工作簿中的工作表中,F列中的单元格变为红色,当它们被单击一次时,它将拉出一张值。我想改变这一点,一旦双击F列中的单元格,然后将拉出一张值。这张表被称为" JE"这是我的代码:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MySheet As String
On Error GoTo Done:
If Target.Column = 6 And Target.Cells.Count = 1 Then
MySheet = WorksheetFunction.VLookup(Target.Offset(0, -2).Value, Sheets("ref_list").Range("$C$1:$D$17"), 2, 0)
Sheets(MySheet).Visible = True
Sheets(MySheet).Activate
End If
Done:
Sheets("acct_codes").Visible = 0
End Sub
我相信在双击"之前我应该把它变成"但我不确定我是否可以按原样保留代码。不完全确定如何完成这个。
答案 0 :(得分:1)
从这里开始:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim MySheet As String
On Error GoTo Done:
If Target.Column = 6 And Target.Cells.Count = 1 Then
Cancel = True
MySheet = WorksheetFunction.VLookup(Target.Offset(0, -2).Value, Sheets("ref_list").Range("$C$1:$D$17"), 2, 0)
Sheets(MySheet).Visible = True
Sheets(MySheet).Activate
End If
Done:
Sheets("acct_codes").Visible = 0
End Sub