+ Reply to Thread
Results 1 to 2 of 2

Macro creating new worksheet. Is it possible to write running code for sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    07-29-2008
    Location
    Australia
    Posts
    1

    Macro creating new worksheet. Is it possible to write running code for sheet

    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
    Last edited by rylo; 07-29-2008 at 09:38 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    If you post to the wrong Forum by mistake, please notify a moderator to remove the duplicated post. I have deleted the other one!
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1