excel event procedure Programmatically created can not triggered at once

myserial

New Member
Joined
Nov 23, 2015
Messages
2
I created a new worksheet's and its 'worksheet_change' event procedure in 'worksheet_change' procedure of a existing worksheet, in its code I also pasted value in the new worksheet created newly, when I ran my code, the new worksheet and its event produce could be created properly, but the action of pasting value to the new worksheet in the same code block could not trigger the its 'worksheet_change' event procedure. please tell me why ? thanks!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
please post your code in between code tags
Code:
or select and use # in WYSIWYG
 
Upvote 0
Private Sub Worksheet_Change(ByVal Target As Range)


Dim VizBasComp As Variant
Dim NewSheetCodeName As String
Dim destin_sheet, main_sheet As Worksheet
Dim bExistedName, bExistedSheet As Boolean
Dim i, lastRow, main_lastR, linkRow, linkCol As Integer
Dim strCode As String
Set main_sheet = Worksheets("主表")

'MsgBox ("lalala")
If Not Intersect(Target, Range("E3")) Is Nothing Then
'determine whether sheet has been existing, otherwise create it and set relate styles.
For Each sht In Worksheets
If sht.Name = Target.Value Then
bExistedSheet = True
End If
Next
If bExistedSheet = False Then
Worksheets.Add(Before:=Worksheets(Worksheets.Count)).Name = Target.Value

'create event procedure
For Each VizBasComp In ThisWorkbook.VBProject.VBComponents
Select Case True
Case VizBasComp.Type = 100
If VizBasComp.Properties("Name").Value = Target.Value Then
NewSheetCodeName = VizBasComp.Properties("_CodeName").Value
Exit For
End If
End Select
Next
With ThisWorkbook.VBProject.VBComponents(NewSheetCodeName).CodeModule
.InsertLines Line:=.CreateEventProc("Change", "Worksheet") + 1, _
String:="msgbox(""bababa"")"
End With
End If

Set destin_sheet = Worksheets(Target.Value)
Cells(Target.Row - 1, Target.Column).Copy destination:= destin_sheet.range("A1")
End Sub

the action of pasting value to 'destin_sheet' can not trigger the 'worksheet_change' procedure created newly.
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top