Hi,
I have a worksheet that utilizes a Worksheet Change Event. I created a macro to copy the sheet and that works fine except for the fact that it doesn't contain the Worksheet Change event. Any idea on how I can do this (if possible) in a macro?
Thanks in advance.
Max57
Last edited by max57; 07-28-2009 at 09:32 PM.
not clear.
suggest you call the macro from within the worksheet change event
worksheet change event occurs when target value changes.
i assume you might mean -
Code:Sub CopyToNewWB() ' copies Sheet1 to a new workbook - sheet code included Activeworkbook.Sheets("Sheet1").Copy after:=Sheets(Sheets.Count) End Sub Sub CopyAsNewSht() ' creates copy of Sheet1 in sameworkbook - sheet code included Activeworkbook.Sheets("Sheet1").Copy End Sub
Hi all,
I had originally used a macro recorder macro and that's where my problem originated from. After reading the posts, I realized that I wasn't copying the Worksheet rather, only the worksheet cells. As a result, I wasn't getting the Worksheet Change event code copied into the new sheet.
I found a very good snippet of code that added a little more functionality to what I wanted to do and adopted it to my needs.
Thank you for your suggestions which inevitably led me to this conclusion.Code:Option Explicit Dim NewPageName As String Sub NewPage() Dim Sheets As Worksheet Set Sheets = Sheet4 Sheets.Visible = True Sheets.Copy After:=Worksheets(Worksheets.Count) NewPageName = InputBox("What would you like to call your new Worksheet") ActiveWindow.ActiveSheet.Name = NewPageName Sheets.Visible = False End Sub
Max57
I wouldn't declare sheets as a variable, use sht or similar instead
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
Check out the free Excel Toolbar
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Code Tags: Make your code easier for us to read
Point well taken.
Thanks for the heads up.
Max57![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks