Forum Discussion
Preshti157
Apr 18, 2023Copper Contributor
Macros on Excel
Hello!
We have an excel sheet which collects data daily, at the end of the week, an average is calculated. When the cell (which has the average written in it) is double clicked, a prompt appears asking to transfer this number to another tab with a graph. Given the user selects yes, the data is transferred to other tab This gives us a visual representation of the data over the weeks.
I would like to copy the macros related to this tab to another tab with the same formatting.
How would I do this?
Thank you.
Code that runs automatically when a cell is double-clicked is a Worksheet_BeforeDoubleClick event procedure, not a "normal" macro.
To inspect the code, right-click the sheet tab and select 'View Code' from the context menu.
Look for
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) ... End Sub
You can copy this procedure, and paste it into the worksheet module of another worksheet, then modify it to suit your needs.
Don't forget to save the workbook into which you copied the code as a macro-enabled workbook (*.xlsm).