不好意思,有了代码我还不知道怎么用,可以教教我吗?
追答打开excel表格,右击你的工作簿标签,选择查看代码,拷如代码即可直接使用此功能。
追问我用了但是无效啊!
追答需要双击选中的单元格,就会自动跳转,并且自动将搜索到得单元格锁定在表格的左上角。
Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim StrFind As String
Dim rng1 As Range
Dim rng2 As Range
StrFind = Selection
If StrFind "" Then
With ActiveSheet.Range(Cells(1, 1), Cells(Selection.Row - 1, 256)) ‘选择当前活动工作簿
Set rng1 = .Find(What:=StrFind, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
With ActiveSheet.Range(Cells(Selection.Row + 1, 1), Cells(Rows.Count, 256)) ‘选择当前活动工作簿
Set rng2 = .Find(What:=StrFind, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
If Not rng1 Is Nothing Then
Application.Goto rng1, True
ElseIf Not rng2 Is Nothing Then
Application.Goto rng2, True
Else
MsgBox "没有找到匹配单元格!"
End If
Else
MsgBox "选中了空单元格!"
End If
Set rng1 = Nothing
Set rng2 = Nothing
End Sub
myselect.FormatConditions(1).Interior.ColorIndex = 7
myselect.FormatConditions(1).Interior.Pattern = xlSolid
End Sub