View Full Version : newly created sheet - assign module

02-10-2015, 08:48 AM
Hello All,

I have an excel workbook with 2 sheets.
Sheet 1: contains a button for creating a new sheet with user data
Sheet 2: contains data for a company and departments (department heads, contact information, etc...)

On Sheet 2, I have worksheet_SelectionChange code that works. Basically if the user clicks on a cell in columns A or F: comments will appear with more detailed information about that cell. If any other column is clicked, nothing happens.

What I am hoping: I want to place the same worksheet_SelectionChange code (with some modification) from Sheet2 in a module. Is there anyway, that when the button on Sheet 1 is clicked and a new sheet is created, I can apply the module code to the worksheet_SelectionChange for that new sheet?

Bob Phillips
02-10-2015, 12:38 PM
Create a template sheet with the code, hide it, and instead of just adding a new sheet copy the template to a new sheet.

02-11-2015, 04:49 PM
Or you could move Sheet2's SelectionChange event to the ThisWorkbook module's SheetSelectionChange event, so it will run on every sheet except Sheet1

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Name <> "Sheet1" Then
' your code here
End If
End Sub