2016-10-18 71 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

相关问题