Sub addinfo()
If Range("FH17") = "Unlocked" Then
Result = MsgBox("Are you sure you want to add information for a new year? (This is only to be done after you have created a new workbook for a new year)", vbYesNo + vbQuestion)
If Result = vbYes Then
Range("FH17").Value = "Locked"
'creating template
Set wk = ThisWorkbook
Dim template As String
template = Sheets("Data").Range("EW12").Value
'add template
wk.Sheets("Data").Range("A1:BC1000").Copy wk.Sheets(template).Range("A1")
'add old info
wk.Sheets("Data").Range("IE5:IK1000").Copy wk.Sheets(template).Range("A5")
wk.Sheets("Data").Range("IL5:IM1000").Copy wk.Sheets(template).Range("J5")
wk.Sheets("Data").Range("IN5:IW1000").Copy wk.Sheets(template).Range("O5")
'change date
wk.Sheets("Data").Range("EX12").Copy wk.Sheets(template).Range("E1")
'copy format to template
wk.Sheets("Data").Range("A:BC").Copy
wk.Sheets(template).Range("A1").Parent.Activate
wk.Sheets(template).Range("A1").PasteSpecial xlPasteColumnWidths
wk.Sheets(template).Range("A1").PasteSpecial xlPasteFormats
Application.CutCopyMode = False
'unhide columns
wk.Sheets(template).Range("A:BC").Select
Selection.EntireColumn.Hidden = False
'Hide columns
wk.Sheets(template).Range("AC:AD").Select
Selection.EntireColumn.Hidden = True
wk.Sheets(template).Range("AM:AN").Select
Selection.EntireColumn.Hidden = True
wk.Sheets(template).Range("AR:AT").Select
Selection.EntireColumn.Hidden = True
wk.Sheets(template).Range("A1").Select
Call rows_freeze
'Protect the sheet
ActiveSheet.Protect
MsgBox "Done."
Else
Range("FH17").Value = "Locked"
End If
End If
End Sub
This is my code, it works fine. except the part of calling on "row_freeze". I tried not having it as 2 macros but that didnt work either. I get a 400 error message. Anyone with any idea? The only part that actually needs to be fixed is the code below, I'm trying to autofit row 3 and then freeze everything above cell A4. (I tried to skip the "Rows("3:3").Select" and that did nothing)(the code works if I do it in a an new empty workbook)
Sub rows_freeze()
Rows("3:3").Select
Rows("3:3").EntireRow.AutoFit
Range("A4").Select
ActiveWindow.FreezePanes = True
End Sub
EDIT: I format the width of the columns, I believe that it sometimes "has time" to make the columns big enough for the text to fit. but sometimes it does not and the "wrap text" causes the rows to get very long(height). I removed both lines of code(rows and freeze) and I dont get any error message (this time the rows actually did not need to be autofitted, but sometimes they do).
EDIT 2:
'copy sheet to new workbook
sheettocopy = Range("EW10").Value
Worksheets(sheettocopy).Copy
Dim wb As Workbook
'Store new workbook into a variable
Set wb = ActiveWorkbook
'Fix any macro assigned buttons
Call FixMacroLinks(wb)
'adding sheet and renaming
Sheets.Add After:=ActiveSheet
ActiveSheet.Name = Sheets("Data").Range("EW12").Value
ActiveWorkbook.Sheets("Data").Activate
MsgBox "Done."
Else
MsgBox "You do not have a december month"
Range("FF17").Value = "Locked"
This is the code when creating the new workbook. The first thing I do when this is done, is to start the "Addinfo" sub