2016-08-03 18 views
-4

VBAレコーダーを使って書いたコードがありますが、最初にロック解除シートを追加して最後にシートをロックしたいと思います。VBAのロックとロック解除

ます。Private Sub CommandButton1_Click()

' ' New_Risk_4マクロ ActiveSheet.UsedRange

Sheets("Risk Template").Select 
'Looks at the risk template sheet' 

ActiveCell.Rows("1:7").EntireRow.Select 
ActiveCell.Offset(0, 4).Range("A1").Activate 
'selects everything within the range' 

Selection.Copy 
'Copies to clipboard' 

Sheets("Risk Input Sheet").Select 
'Switches back to Risk Input sheet' 

ActiveCell.SpecialCells(xlLastCell).Select 
'Selects last active cell' 

ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select 
'Selects row with last active cell' 

ActiveSheet.Paste 
'Paste to select row' 
+0

なぜドン」あなたはちょうどそれを追加しますか?あなたの質問は何ですか? –

+0

あなたの問題は何ですか? –

+0

[VBAイベント - 選択されている場合、保護されたシートのセルのロックを解除する]の可能な複製(http://stackoverflow.com/questions/27332602/vba-event-unlock-cell-in-protected-sheets-if-selected) – DragonSamu

答えて

-1

'最後のアクティブセルをリセット' は、それを完了します!

ます。Private Sub CommandButton1_Click()

ActiveSheet.Unprotect ' ' New_Risk_4マクロ ActiveSheet.UsedRange

Sheets("Risk Template").Select 
'Looks at the risk template sheet' 

ActiveCell.Rows("1:7").EntireRow.Select 
ActiveCell.Offset(0, 4).Range("A1").Activate 
'selects everything within the range' 

Selection.Copy 
'Copies to clipboard' 

Sheets("Risk Input Sheet").Select 
'Switches back to Risk Input sheet' 

ActiveCell.SpecialCells(xlLastCell).Select 
'Selects last active cell' 

ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select 
'Selects row with last active cell' 

ActiveSheet.Paste 
'Paste to select row' 

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _ 
    , AllowFormattingCells:=True, AllowFormattingColumns:=True, _ 
    AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _ 
    :=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _ 
    AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _ 
    AllowUsingPivotTables:=True 

End Subの '最後のアクティブセルをリセット'

関連する問題