Consulting

Results 1 to 8 of 8

Thread: Archiving weekly data

  1. #1

    Archiving weekly data

    Hi,

    I have found some code on here that almost does what I need it to do the code is:
    [VBA]Private Sub CommandButton2_Click()
    Dim NewName As String
    Dim nm As Name
    Dim ws As Worksheet

    If MsgBox("Copy specific sheets to a new workbook" & vbCr & _
    "New sheets will be pasted as values, named ranges removed" _
    , vbYesNo, "NewCopy") = vbNo Then Exit Sub

    With Application
    .ScreenUpdating = False

    ' Copy specific sheets
    ' *SET THE SHEET NAMES TO COPY BELOW*
    ' Array("Sheet Name", "Another sheet name", "And Another"))
    ' Sheet names go inside quotes, seperated by commas
    On Error GoTo ErrCatcher
    Sheets(Array("SAT Data")).Copy
    On Error GoTo 0

    ' Paste sheets as values
    ' Remove External Links, Hperlinks and hard-code formulas
    ' Make sure A1 is selected on all sheets
    For Each ws In ActiveWorkbook.Worksheets
    ws.Cells.Copy
    ws.[A1].PasteSpecial Paste:=xlValues
    ws.Cells.Hyperlinks.Delete
    Application.CutCopyMode = False
    Cells(1, 1).Select
    ws.Activate
    Next ws
    Cells(1, 1).Select

    ' Remove named ranges
    For Each nm In ActiveWorkbook.Names
    nm.Delete
    Next nm

    ' Input box to name new file
    NewName = InputBox("Weekly SAT Records 2011", "New Copy")

    ' Save it with the NewName and in the same directory as original
    ActiveWorkbook.SaveCopyAs ThisWorkbook.Path & "\" & NewName & ".xls"
    ActiveWorkbook.Close SaveChanges:=False

    .ScreenUpdating = True
    End With
    Exit Sub

    ErrCatcher:
    MsgBox "Specified sheets do not exist within this workbook"
    End Sub[/VBA]

    What I need is:

    I have a file that contains a front sheet 'SAT Data' that is filled out every friday. This has links to trend analysis. What I need to do is save the front sheet to another file called 'Weekly SAT Records 2011' . Saved on a new sheet each time and named with the week commencing date in cell J1.

    The above runs and falls over at the point with the head banging smiley. A copy is produced and opened up as 'Book1' then if I click th button again another copy is produced as 'Book2'

    Can someone help me to sort this please,

    By the way, I fumble through these codes with the elegance of an hippo i.e. I'm not that clued up !!!

    Regards,

    Andy.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No head banging smiley that I can see.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    hI,

    When posted the headbanging smiley didn't show up as a character the line that starts with is the line where it stops, is not part of the code !

    Regards,

    Andy

  4. #4
    [ : banghead : ]


    gerrrrr

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

    [vba]

    For Each ws In ActiveWorkbook.Worksheets
    ws.Cells.Copy
    ws.[A1].PasteSpecial Paste:=xlValues
    ws.Cells.Hyperlinks.Delete
    Application.CutCopyMode = False
    ws.Activate
    ws.Cells(1, 1).Select
    Next ws
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Thanks Xld,

    after a little more fiddling now works brilliantly

    One small problem, whan the sheet is saved the two buttons I have for 'Update' and 'Archive' are saved into the archive file along with the codeing. Is it posible to strip these off when archiving the sheet ?

    Best regards,

    Andy.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What sort of buttons?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    Command Buttons

    if that helps ?

Posting Permissions

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