This is my current macro that runs from a button, I need to have it so that when i change entries on the page created it also changes it on the Source page (Foreman Prepworks).
Sub Button6_Click()
Dim WS As Worksheet
Dim WSNew As Worksheet
Dim rng As Range
Dim rng2 As Range
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set WS = Sheets("Foreman Prepworks")
Set rng = WS.Range("A5:AV" & Rows.Count)
WS.AutoFilterMode = False
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Foreman Prep Filter").Delete
Application.DisplayAlerts = True
On Error GoTo 0
rng.AutoFilter Field:=3, Criteria1:="=CS"
Set WSNew = Worksheets.Add
WSNew.Name = "Foreman Prep Filter"
WS.AutoFilter.Range.Copy
With WSNew.Range("A5")
.PasteSpecial Paste:=8
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
.Select
End With
With ActiveSheet.Buttons.Add(48, 13, 96, 26).Select
Selection.OnAction = "DisplayMessage"
ActiveSheet.Shapes("Button 1").Select
Selection.Characters.Text = "Back"
With Selection.Characters(Start:=1, Length:=20).Font
.Name = "Times New Roman"
.FontStyle = "Bold"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("A1").Select
End With
WS.AutoFilterMode = False
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
I have tried to add in the code to the worksheet that will copy the data back to the Main page, the code i used is below:
If Not Intersect(Target(1, 1), Range("AV5:AV250")) Is Nothing Then
Sheets(Array(Me.Name, "Foreman Prep Filter", "Foreman Prepworks")).Select
Else
Me.Select
End If
The problem I'm having is when It recreates the page for another filtered option it wipes this code from the tab. Basically I'm wondering if it is possible to get the original macro to write this code everytime it creates the sheet.
Any answers?
Kind Regards,
Tom
Bookmarks