2016-10-18 113 views
0

我希望您能提前幫助並提前致謝。我有一個下面的代碼,我想添加一個代碼凍結/鎖定單元格$H$3。請幫忙。VBA鎖定當前代碼中的單個單元格

Sub Copy_Tabs_New() 
Dim x, ListItem As Variant 
Dim numtimes As Byte 
x = InputBox("Enter number of times to copy 4075 Wilson") 
If Not IsNumeric(x) Then Exit Sub 
If (x < 1) Or (x > 55) Then Exit Sub 
ActiveWorkbook.Sheets("4075 Wilson").Select 
ListItem = Range("C3").Value 
Application.ScreenUpdating = False 
For numtimes = 1 To x 
    ActiveWorkbook.Sheets("4075 Wilson").Copy After:=ActiveSheet 
    Range("H3").Value = ListItem 
    Range("C3").Value = Range("B2").Value 
    ListItem = Range("C3").Value 
Next 
ActiveWorkbook.Sheets("4075 Wilson").Select 
Application.ScreenUpdating = True 
End Sub 

回答

0

如何:

Sub Copy_Tabs_New() 
    Dim x, ListItem As Variant 
    Dim numtimes As Byte 

    x = InputBox("Enter number of times to copy 4075 Wilson") 
    If Not IsNumeric(x) Then Exit Sub 
    If (x < 1) Or (x > 55) Then Exit Sub 
    ActiveWorkbook.Sheets("4075 Wilson").Select 
    ListItem = Range("C3").Value 
    Application.ScreenUpdating = False 
    For numtimes = 1 To x 
     ActiveWorkbook.Sheets("4075 Wilson").Copy After:=ActiveSheet 
     Range("H3").Value = ListItem 
     Call freeeze 
     Range("C3").Value = Range("B2").Value 
     ListItem = Range("C3").Value 
    Next 
    ActiveWorkbook.Sheets("4075 Wilson").Select 
    Application.ScreenUpdating = True 
End Sub 

Sub freeeze() 
    With ActiveSheet 
     .Unprotect 
     .Cells.Locked = False 
     .Range("H3").Locked = True 
     .Protect 
    End With 
End Sub 
+0

非常感謝您!它運作良好! – CaL

相關問題