Sub ChangeMacroCode()
Dim sCodeName As String
Dim LineNum As Long
' Get the codename of the newly created sheet
sCodeName = Worksheets("Working Data").CodeName 'new worksheet name
' Write some text in the module
With ActiveWorkbook.VBProject.VBComponents(sCodeName).CodeModule
LineNum = .CountOfLines + 1
If .CountOfLines > 0 Then .DeleteLines (1)
.InsertLines LineNum, "Private Sub Worksheet_Change(ByVal Target As Range)"
LineNum = LineNum + 1
.InsertLines LineNum, "Application.ScreenUpdating = False"
LineNum = LineNum + 1
.InsertLines LineNum, "If Target.Address = ""$C$2"" Then"
LineNum = LineNum + 1
.InsertLines LineNum, " Dim LastRow As Long"
LineNum = LineNum + 1
.InsertLines LineNum, " LastRow = Cells(Rows.Count, 4).End(xlUp).Row"
LineNum = LineNum + 1
.InsertLines LineNum, " Range(""D2"", ""D"" & LastRow).ClearContents"
LineNum = LineNum + 1
.InsertLines LineNum, " Call ListServers"
LineNum = LineNum + 1
.InsertLines LineNum, "End If"
LineNum = LineNum + 1
.InsertLines LineNum, "If Target.Address = ""$F$2"" Then"
LineNum = LineNum + 1
.InsertLines LineNum, " Dim LastRow As Long"
LineNum = LineNum + 1
.InsertLines LineNum, " LastRow = Cells(Rows.Count, 4).End(xlUp).Row"
LineNum = LineNum + 1
.InsertLines LineNum, " Range(""G2"", ""G"" & LastRow).ClearContents"
LineNum = LineNum + 1
.InsertLines LineNum, " Call ListApps"
LineNum = LineNum + 1
.InsertLines LineNum, "End If"
LineNum = LineNum + 1
.InsertLines LineNum, "Application.ScreenUpdating = True"
LineNum = LineNum + 1
.InsertLines LineNum, "End Sub"
End With
End Sub