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".
Thanks a lot!
<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".
Thanks a lot!