"Double Click" macro?

C

Cerberus

Is there a way to create a macro that if you double click on a cell or row it
will activate a worksheet. Example would be:

If cell A1 is double clicked, or at least activated and "submitted" using a
Command Button, the result would be:

Worksheets ("12").Activate

See I have 94 rows of assembly descriptions on a worksheet
[Worksheets("Start")], and 94 other worksheets that have a Bill Of Materials.
I would like to have a person be able to highlight a cell or row and it
brings up the correct BOM. A double click would be easiest on the end user
but I think an active row or cell with a Command Button is more achievable.

Any help is greatly appreciated. Thanks in advance.
 
G

Gary''s Student

Here is a double-click example. Once installed, if you double click on B9 it
takes you to another sheet:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Set t = Target
Set r = Range("B9")
If Intersect(t, r) Is Nothing Then Exit Sub
Sheets("Sheet1").Activate
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm
 
C

Cerberus

Great, thank you!

Gary''s Student said:
Here is a double-click example. Once installed, if you double click on B9 it
takes you to another sheet:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Set t = Target
Set r = Range("B9")
If Intersect(t, r) Is Nothing Then Exit Sub
Sheets("Sheet1").Activate
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200907


Cerberus said:
Is there a way to create a macro that if you double click on a cell or row it
will activate a worksheet. Example would be:

If cell A1 is double clicked, or at least activated and "submitted" using a
Command Button, the result would be:

Worksheets ("12").Activate

See I have 94 rows of assembly descriptions on a worksheet
[Worksheets("Start")], and 94 other worksheets that have a Bill Of Materials.
I would like to have a person be able to highlight a cell or row and it
brings up the correct BOM. A double click would be easiest on the end user
but I think an active row or cell with a Command Button is more achievable.

Any help is greatly appreciated. Thanks in advance.
 
G

Gary''s Student

You are very welcome, but also consider using a hyperlink to accomplish the
same thing. The hyperlink only needs a single click (you see I am very lazy!)
--
Gary''s Student - gsnu200907


Cerberus said:
Great, thank you!

Gary''s Student said:
Here is a double-click example. Once installed, if you double click on B9 it
takes you to another sheet:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Set t = Target
Set r = Range("B9")
If Intersect(t, r) Is Nothing Then Exit Sub
Sheets("Sheet1").Activate
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200907


Cerberus said:
Is there a way to create a macro that if you double click on a cell or row it
will activate a worksheet. Example would be:

If cell A1 is double clicked, or at least activated and "submitted" using a
Command Button, the result would be:

Worksheets ("12").Activate

See I have 94 rows of assembly descriptions on a worksheet
[Worksheets("Start")], and 94 other worksheets that have a Bill Of Materials.
I would like to have a person be able to highlight a cell or row and it
brings up the correct BOM. A double click would be easiest on the end user
but I think an active row or cell with a Command Button is more achievable.

Any help is greatly appreciated. Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top