有一天,我学会了如何使用VBA双击在Sheet1中单元格,然后它会跳转到细胞具有相同的值在表2VBA搜索所有工作表双单击的单元格值
我有一个类似的报告现在,除了这次我需要双击Sheet1中的一个单元格,然后搜索同一工作簿中的每个工作表以获取该值。
我有,工程的第一个场景中的代码是在这里: 在的ThisWorkbook:
Private Sub Workbook_SheetBeforeDoubleClick _
(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
If Len(Target.Value) = 0 Then Exit Sub
'If the double-clicked cell isn't in column A, we exit.
If Target.Column <> 1 Then Exit Sub
'Calls the procedure FindName in Module1 and passes the cell content
Module1.FindName Target.Value
End Sub
在模块1:
Sub FindName(ByVal sName As String)
'Finds and activates the first cell
'with the same content as the double-clicked cell. sName
'is the passed cell content.
Dim rColumn As Range
Dim rFind As Range
'Activate the sheet Contact Data.
Worksheets("All Data").Activate
'Set the range rColumn = column B
Set rColumn = Columns("B:B")
'Search column B
Set rFind = rColumn.Find(sName)
'If found the cell is activated.
If Not rFind Is Nothing Then
rFind.Activate
Else
'If not found activate cell A1
Range("A1").Activate
End If
Set rColumn = Nothing
Set rFind = Nothing
End Sub
如果有人知道如何也许在此创建工作表圈所以它会在每个工作表中寻找价值,我会很感激!
谢谢! Emmily 我对以前的代码来源:http://www.sitestory.dk/excel_vba/hyperlinks-alternative.htm
“大斯科茨”再次同步 –
@SCOTTHOLTZMAN非常感谢您的快速响应!我试图运行此代码,我在第一个错误行:编译错误:用户定义的类型没有定义任何想法? – Emmily
@Emmily - '工作表在'昏暗的ws作为工作表''有一个太多'e's。我编辑我的代码,再试一次 –