有一天,我學會了如何使用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。我編輯我的代碼,再試一次 –