Double click cell to open a specific work sheet

sophie_san

New Member
Joined
Jun 18, 2018
Messages
2
I have found the VBA code to solve the above mentioned problem - but it will only work for one cell per sheet:

<code class="vb keyword">Private</code> <code class="vb keyword">Sub</code> <code class="vb plain">Worksheet_BeforeDoubleClick(</code><code class="vb keyword">ByVal</code> <code class="vb plain">Target </code><code class="vb keyword">As</code> <code class="vb plain">Range, Cancel </code><code class="vb keyword">As</code> <code class="vb keyword">Boolean</code><code class="vb plain">)</code>
<code class="vb spaces"> </code><code class="vb keyword">Dim</code> <code class="vb plain">xStr </code><code class="vb keyword">As</code> <code class="vb keyword">String</code>
<code class="vb spaces"> </code><code class="vb plain">xStr = </code><code class="vb string">"Sheet name"</code>
<code class="vb spaces"> </code><code class="vb keyword">If</code> <code class="vb keyword">Not</code> <code class="vb plain">Intersect(Target, Range(</code><code class="vb string">"A1"</code><code class="vb plain">)) </code><code class="vb keyword">Is</code> <code class="vb keyword">Nothing</code> <code class="vb keyword">Then</code>
<code class="vb spaces"> </code><code class="vb plain">Sheets(xStr).Activate</code>
<code class="vb spaces"> </code><code class="vb keyword">End</code> <code class="vb keyword">If</code>
<code class="vb keyword">End</code> <code class="vb keyword">Sub</code>



Is it possible to have lots of these codes on one sheet, to have double click on A1 do this, double click on A2 do that etc.? How do I do it? Just keep copying the code above (with adjustments to sheet name and ("A1") did not work... the error message told me "Compile error: Ambiguous name detected: Worksheet_BeforeCoubleClick". :confused:

Thanks a lot!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi & welcome to the board.
How about
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Not Intersect(Target, Range("A1:A5")) Is Nothing Then
      Sheets(Choose(Target.row, "[COLOR=#ff0000]HPTOOL[/COLOR]", "[COLOR=#ff0000]Fluff[/COLOR]", "[COLOR=#ff0000]Pcode[/COLOR]", "[COLOR=#ff0000]Pick[/COLOR]", "[COLOR=#ff0000]MA[/COLOR]")).Activate
      Cancel = True
   End If
End Sub
Change the values in red to match you sheet names.
This will work for cells A1 to A5
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top