我有几个使用这个完全相同的代码的子代码,但是这个代码返回
运行时错误'1004':
删除Range类失败的方法
drill.Range("48:48").Delete
在其他方面它运作得很好,但在这一方面却没有
Sub Drill_Log_Undo()
'
'takes the last submited drill log and places it back into the submission line
'
'Unprotects Drill Log
Worksheets("Drill Log").Unprotect "Welcome1"
'Declares Variables
Dim drill As Worksheet: Set drill = Worksheets("Drill Log")
Dim start_joint As Range: Set start_joint = drill.Range("C48")
Dim start_time As Range: Set start_time = drill.Range("F48")
Dim info As Range: Set info = drill.Range("G48:S48")
Dim tool_used As Range: Set tool_used = drill.Range("E48")
Dim pass_type As Range: Set pass_type = drill.Range("D48")
Dim x As Integer
x = 0
'coppies the data to the submission line
drill.Range("G37:S37").Value = drill.Range("G48:S48").Value 'to Multi
drill.Range("G35:S35").Value = drill.Range("G48:S48").Value 'to Single
'changes the pass type to the previously entered pass type
drill.Range("K10").Value = pass_type.Value
'determins whether the pass was multiple or single
If drill.Range("F48") = Null Or drill.Range("F48") = "" Then
'adds the end joint to the end joint submission cell
drill.Range("C37").Value = drill.Range("C48")
'counts the number of joints and removes them as it goes
Do Until drill.Range("A59").Value = Null
If start_time.Value = "" Or Null Then
以下是抛出代码的行
drill.Range("48:48").Delete
结束行
x = x + 1
Set start_time = drill.Range("F48")
Else
drill.Range("F37").Value = drill.Range("F48").Value
Exit Do
End If
Loop
'adds the last joint to the joint count and removes the joint row
drill.Range("B37") = drill.Range("C48")
x = x + 1
drill.Range("48:48").Delete
Else
End If
'protects Drill Log
Worksheets("Drill Log").Protect "Welcome1"
End Sub
我尝试了不同的方式来声明变量,我甚至尝试通过调用行中的工作簿和工作表来专门调用代码。
答案 0 :(得分:0)
将drill.Range("48:48").Delete
替换为drill.Rows("48").EntireRow.Delete