Hi all,
Need some help please.
The macro I have created currently creates a new sheet from a current one (copies it exactly and then changes a few things in the sheet as per what I have asked it to do). The macro is currently working fine and does what I want it to do, however I've noticed that it's not copying over the worksheet protection options from the original, i.e. allow users to: Format cells, format columns, format rows...etc...
After searching the forums I have found this:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True
I tried inserting it into my current one but it's not working. The current one is this (without the above inserted):
Sub CreateProductionSampleSpec()
'
' Macro5 Macro
'
'
Application.ScreenUpdating = False
ThisWorkbook.Unprotect Password:="password"
ActiveSheet.CheckBoxes.Add(869.25, 131.25, 15, 15.75).Select
Sheets("GRADED SIZE SPEC").Copy Before:=Sheets(12)
Sheets("GRADED SIZE SPEC (2)").Select
Sheets("GRADED SIZE SPEC (2)").Name = "PRODUCTION SAMPLES"
Sheets("PRODUCTION SAMPLES").Select
With ActiveWorkbook.Sheets("PRODUCTION SAMPLES").Tab
.Color = 65535
.TintAndShade = 0
End With
ActiveSheet.Unprotect Password:="password"
Range("C2:S2").Select
ActiveCell.FormulaR1C1 = "PRODUCTION SAMPLES"
Range("M7:S7").Select
ActiveSheet.Shapes.Range(Array("Check Box 1")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("TextBox 5")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("TextBox 4")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("TextBox 3")).Select
Selection.Delete
Range("Q8:S8").Select
Selection.ClearContents
Range("J8:P8").Select
Selection.ClearContents
Range("J8:S8").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("T4:Z4").Select
Selection.Copy Destination:=Range("J8:P8")
Range("P8").Select
Selection.AutoFill Destination:=Range("P8:S8"), Type:=xlFillDefault
Range("P8:S8").Select
Range("J5:S7").Select
Range("M7").Activate
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("M7:S7").Select
Selection.ClearContents
Columns("T:Z").Select
Selection.EntireColumn.Hidden = True
Range("M7:S7").Select
ActiveWindow.SmallScroll Down:=-21
ActiveSheet.Protect Password:="password"
ThisWorkbook.Protect Password:="password"
Application.ScreenUpdating = True
End Sub
Can someone please help
Thank you
Nisha
Need some help please.
The macro I have created currently creates a new sheet from a current one (copies it exactly and then changes a few things in the sheet as per what I have asked it to do). The macro is currently working fine and does what I want it to do, however I've noticed that it's not copying over the worksheet protection options from the original, i.e. allow users to: Format cells, format columns, format rows...etc...
After searching the forums I have found this:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True
I tried inserting it into my current one but it's not working. The current one is this (without the above inserted):
Sub CreateProductionSampleSpec()
'
' Macro5 Macro
'
'
Application.ScreenUpdating = False
ThisWorkbook.Unprotect Password:="password"
ActiveSheet.CheckBoxes.Add(869.25, 131.25, 15, 15.75).Select
Sheets("GRADED SIZE SPEC").Copy Before:=Sheets(12)
Sheets("GRADED SIZE SPEC (2)").Select
Sheets("GRADED SIZE SPEC (2)").Name = "PRODUCTION SAMPLES"
Sheets("PRODUCTION SAMPLES").Select
With ActiveWorkbook.Sheets("PRODUCTION SAMPLES").Tab
.Color = 65535
.TintAndShade = 0
End With
ActiveSheet.Unprotect Password:="password"
Range("C2:S2").Select
ActiveCell.FormulaR1C1 = "PRODUCTION SAMPLES"
Range("M7:S7").Select
ActiveSheet.Shapes.Range(Array("Check Box 1")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("TextBox 5")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("TextBox 4")).Select
Selection.Delete
ActiveSheet.Shapes.Range(Array("TextBox 3")).Select
Selection.Delete
Range("Q8:S8").Select
Selection.ClearContents
Range("J8:P8").Select
Selection.ClearContents
Range("J8:S8").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.UnMerge
Range("T4:Z4").Select
Selection.Copy Destination:=Range("J8:P8")
Range("P8").Select
Selection.AutoFill Destination:=Range("P8:S8"), Type:=xlFillDefault
Range("P8:S8").Select
Range("J5:S7").Select
Range("M7").Activate
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("M7:S7").Select
Selection.ClearContents
Columns("T:Z").Select
Selection.EntireColumn.Hidden = True
Range("M7:S7").Select
ActiveWindow.SmallScroll Down:=-21
ActiveSheet.Protect Password:="password"
ThisWorkbook.Protect Password:="password"
Application.ScreenUpdating = True
End Sub
Can someone please help
Thank you
Nisha