在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 Sheet1.Range(Cells(1, 1), Cells(Selection.Row - 1, 1))
Set rng1 = .Find(What:=StrFind, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With

With Sheet1.Range(Cells(Selection.Row + 1, 1), Cells(Rows.Count, 1))
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追问

不好意思,有了代码我还不知道怎么用,可以教教我吗?

追答

打开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

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-03-26
没听说过。你CTRL+F,搜索你要找的内容,效果不是样吗?
第2个回答  2012-03-26
没明白什么意思,能说的详细一点吗
相似回答