Below I have added a code that I have had loads of help producing and would like to share with the forum.
I have an excel workbook that is filled out once a week, the front sheet is filled out with the information required and I have a command button 'Update' that is clicked and th relevant information is taken from th front sheet and updated on the rest of the sheets in the workbook, this is then attached to graphs enabling to view trends.
I need to keep the front sheet as evidence and so I have a second command button 'Archive' this is clicked, select yes from the box, enter the file name (I use week commencing date) in the box and enter. the front sheet is now Archived in the same folder as the original workbook. On closeing the file select yes when asked if you wish to save changes. This is then ready to fill in next time. I can provide the workbook if somone once to have a look at it working.
A couple of questions
1. Can I strip the command buttons from the front sheet in the archive file, if so could someone help with a code.
2. Can the archived files be auto protected against anyone trying to make changes, again if so, could someone help and provide code to achieve this.
3. How can set the graphs so they update throughout the year, I don't really want to select the 'source data' area for a whole year because the info is so small untill you have been filling it out for a few months but also editing the 'source data' every week is a pain.
Thankyou for any help to achieve this so far,
Best regards,
Andy.
Private Sub CommandButton1_Click()
Dim i As Long, r As Range
Application.ScreenUpdating = False
With Sheets(1)
i = 1
For Each r In .Range("G10", .Range("G10").End(xlDown))
i = i + 1
r.Resize(, 4).Copy
Sheets(i).Cells(Rows.Count, 2).End(xlUp)(2).PasteSpecial xlPasteValuesAndNumberFormats
Next r
End With
Application.ScreenUpdating = True
End Sub
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
ws.Activate
ws.Cells(1, 1).Select
Next ws
' 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
Bookmarks