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.