Przejdź do głównej zawartości

Jak dwukrotnie kliknąć komórkę, aby otworzyć określony arkusz w programie Excel?

Czy chcesz szybko przejść do określonego arkusza w skoroszycie programu Excel? W tym artykule znajdziesz metodę VBA do otwierania określonego arkusza roboczego przez dwukrotne kliknięcie określonej komórki w programie Excel.

Kliknij dwukrotnie komórkę, aby otworzyć określony arkusz z kodem VBA


Kliknij dwukrotnie komórkę, aby otworzyć określony arkusz z kodem VBA

Wykonaj następujące czynności, aby otworzyć określony arkusz roboczy, klikając dwukrotnie komórkę w programie Excel.

1. Kliknij prawym przyciskiem myszy kartę arkusza zawierającą komórkę, którą chcesz otworzyć arkusz roboczy, klikając ją. A następnie kliknij Wyświetl kod z menu kontekstowego. Zobacz zrzut ekranu:

2. W otwarciu Microsoft Visual Basic for Applications okno, proszę skopiować następujący kod VBA do okna Code.

Kod VBA: kliknij dwukrotnie komórkę, aby otworzyć określony arkusz w programie Excel

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Updated by Extendoffice 20180822
Dim xArray, xAValue As Variant
Dim xFNum As Long
Dim xStr, xStrRg, xStrSheetName As String
xRgArray = Array("A1;Sheet2", "A12;Sheet3", "A4;Sheet4", "A100;Sheet5")
On Error Resume Next
For xFNum = LBound(xRgArray) To UBound(xRgArray)
xStr = ""
xStr = xRgArray(xFNum)
xAValue = ""
xAValue = Split(xStr, ";")
xStrRg = ""
xStrRg = xAValue(0)
xStrSheetName = ""
xStrSheetName = xAValue(1)
If Not Intersect(Target, Range(xStrRg)) Is Nothing Then
Sheets(xStrSheetName).Activate
End If
Next
End Sub

Note: W kodzie VBA „A1;Arkusz2""A12;Arkusz3""A4;Arkusz4""A100;Arkusz5" oznacza, że ​​podwójne kliknięcie komórki A1 otworzy Arkusz 2, podwójne kliknięcie A2 otworzy Arkusz 3..., zmień je w zależności od potrzeb.

3. wciśnij inny + Q klucze razem, aby zamknąć Microsoft Visual Basic for Applications okno.

Odtąd dwukrotne kliknięcie komórki A1 w bieżącym arkuszu spowoduje natychmiastową aktywację określonego arkusza.


Podobne artykuły:

Najlepsze narzędzia biurowe

🤖 Pomocnik AI Kutools: Zrewolucjonizuj analizę danych w oparciu o: Inteligentne wykonanie   |  Wygeneruj kod  |  Twórz niestandardowe formuły  |  Analizuj dane i generuj wykresy  |  Wywołaj funkcje Kutools...
Popularne funkcje: Znajdź, wyróżnij lub zidentyfikuj duplikaty   |  Usuń puste wiersze   |  Łącz kolumny lub komórki bez utraty danych   |   Okrągły bez wzoru ...
Super wyszukiwanie: Wiele kryteriów VLookup    Wiele wartości VLookup  |   Przeglądanie pionowe na wielu arkuszach   |   Wyszukiwanie rozmyte ....
Zaawansowana lista rozwijana: Szybko twórz listę rozwijaną   |  Zależna lista rozwijana   |  Lista rozwijana wielokrotnego wyboru ....
Menedżer kolumn: Dodaj określoną liczbę kolumn  |  Przesuń kolumny  |  Przełącz stan widoczności ukrytych kolumn  |  Porównaj zakresy i kolumny ...
Polecane funkcje: Fokus siatki   |  Widok projektu   |   Duży pasek formuły    Menedżer skoroszytów i arkuszy   |  Biblioteka zasobów (Automatyczny tekst)   |  Selektor dat   |  Połącz arkusze   |  Szyfruj/odszyfruj komórki    Wysyłaj e-maile według listy   |  Super filtr   |   Specjalny filtr (filtruj pogrubienie/kursywa/przekreślenie...) ...
15 najlepszych zestawów narzędzi12 Tekst Tools (Dodaj tekst, Usuń znaki, ...)   |   50 + Wykres rodzaje (Wykres Gantta, ...)   |   40+ Praktyczne Wzory (Oblicz wiek na podstawie urodzin, ...)   |   19 Wprowadzenie Tools (Wstaw kod QR, Wstaw obraz ze ścieżki, ...)   |   12 Konwersja Tools (Liczby na słowa, Przeliczanie walut, ...)   |   7 Połącz i podziel Tools (Zaawansowane wiersze łączenia, Podział komórki, ...)   |   ... i więcej

Zwiększ swoje umiejętności Excela dzięki Kutools for Excel i doświadcz wydajności jak nigdy dotąd. Kutools dla programu Excel oferuje ponad 300 zaawansowanych funkcji zwiększających produktywność i oszczędzających czas.  Kliknij tutaj, aby uzyskać funkcję, której najbardziej potrzebujesz...

Opis


Karta Office wprowadza interfejs z zakładkami do pakietu Office i znacznie ułatwia pracę

  • Włącz edycję i czytanie na kartach w programach Word, Excel, PowerPoint, Publisher, Access, Visio i Project.
  • Otwieraj i twórz wiele dokumentów w nowych kartach tego samego okna, a nie w nowych oknach.
  • Zwiększa produktywność o 50% i redukuje setki kliknięć myszką każdego dnia!
Comments (14)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Can't get the code to open the other worksheet
This comment was minimized by the moderator on the site
Hi Will,Is there any prompts while using the code?
This comment was minimized by the moderator on the site
Can't get code to open the other sheet, can some help
This comment was minimized by the moderator on the site
hi!
It cannot accept the code for more than 59 sheets.
What code do i need to use to insert more sheets.
When it change the line the code doesnt work.
Help!
This comment was minimized by the moderator on the site
Hi Crystal

I have copied the code and edited according to the name of the worksheets. The code is running but I still cannot open the sheets, what have I done wrong?

Sub OpenbyDoubleclicking(ByVal Target As Range, Cancel As Boolean)

Dim xArray, xAvlaue As Variant '
Dim xFSum As Long
Dim xStr, xStrRg, xStrSheetname As String
xRgArray = Array("A3;FTIR", "A4;Viscometer")
On Error Resume Next
For xFNum = LBound(xRgArray) To UBound(xRgArray)
xStr = ""
xStr = xRgArray(xFNum)
xAValue = ""
xAValue = Split(xStr, ";")
xStrRg = ""
xStrRg = xAValue(0)
xStrSheetname = xAValue(1)
If Not Intersect(Target, Range(xStrRg)) Is Nothing Then _
Sheets(xStrSheetname).Active
End If
Next
End Sub


Many thanks
This comment was minimized by the moderator on the site
Hi Carl,
In your code, please replace the first line with "Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)".
Thank you for your comment. The entire code should be as follows.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim xArray, xAValue As Variant
Dim xFNum As Long
Dim xStr, xStrRg, xStrSheetName As String
xRgArray = Array("A3;FTIR", "A4;Viscometer")
On Error Resume Next
For xFNum = LBound(xRgArray) To UBound(xRgArray)
xStr = ""
xStr = xRgArray(xFNum)
xAValue = ""
xAValue = Split(xStr, ";")
xStrRg = ""
xStrRg = xAValue(0)
xStrSheetName = ""
xStrSheetName = xAValue(1)
If Not Intersect(Target, Range(xStrRg)) Is Nothing Then
Sheets(xStrSheetName).Activate
End If
Next
End Sub
This comment was minimized by the moderator on the site
Hi how can i extend my array? it stucks already and i cannot add more of this because it limits to col 1024 only for that line. pls help

xRgArray = Array("A2;Sheet2", "A3;Sheet3", "A4;Sheet4", "A5;Sheet5")
This comment was minimized by the moderator on the site
Hi Neil,
The code works well in my case even extended my array to Array = Array("A2;Sheet2", "A3;Sheet3", "A4;Sheet4", "A5;Sheet5", "A6;Sheet6").
Can you tell me your Excel version?
This comment was minimized by the moderator on the site
After you get to the desired sheet. Is there a way to copy information from a cell in that sheet and automatically go back to the cell I double clicked on originally in the first sheet?
This comment was minimized by the moderator on the site
Hi James
You need to manually click the original worksheet tab to back to it. Sorry can't take this into consideration.
This comment was minimized by the moderator on the site
Is there a way to do multiple codes for one tab? such as clicking on another cell to jump into another worksheet.

How would that code look like?
This comment was minimized by the moderator on the site
Good day,

The below VBA code can help you to solve the problem. Thanks for your comment.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim xArray As Variant
Dim xFNum As Long
Dim xStr, xStrRg, xStrSheetName As String
xRgArray = Array("A2;Sheet2", "A3;Sheet3", "A4;Sheet4", "A5;Sheet5")
On Error Resume Next
For xFNum = LBound(xRgArray) To UBound(xRgArray)
xStr = ""
xStr = xRgArray(xFNum)
xStrRg = ""
xStrRg = Left(xStr, 2)
xStrSheetName = ""
xStrSheetName = Right(xStr, Len(xStr) - 3)
If Not Intersect(Target, Range(xStrRg)) Is Nothing Then
Sheets(xStrSheetName).Activate
End If
Next
End Sub
This comment was minimized by the moderator on the site
Hi, In the line that states xStrRg = Left(xStr, 2), this picks up the cell if its a single number cell i.e. A1, A2, A3. but not if its A11, or A111. how do i write the code to allow me to use cells A1, A11, and A111?

Hope this makes sense, i'm not particularly technical!!
This comment was minimized by the moderator on the site
Good Day,
The code has been optimized again. Please have a try and thanks for your comment.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim xArray, xAValue As Variant
Dim xFNum As Long
Dim xStr, xStrRg, xStrSheetName As String
xRgArray = Array("A1;Sheet2", "A12;Sheet3", "A4;Sheet4", "A100;Sheet5")
On Error Resume Next
For xFNum = LBound(xRgArray) To UBound(xRgArray)
xStr = ""
xStr = xRgArray(xFNum)
xAValue = ""
xAValue = Split(xStr, ";")
xStrRg = ""
xStrRg = xAValue(0)
xStrSheetName = ""
xStrSheetName = xAValue(1)
If Not Intersect(Target, Range(xStrRg)) Is Nothing Then
Sheets(xStrSheetName).Activate
End If
Next
End Sub
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations