我有两个宏,除了命名的范围差异外,它们是相同的。我通过VBA手动定义或定义的一些命名范围。第一个宏(CleanProcesses)工作正常但第二个宏给我带来了一个错误,即“应用程序定义的错误”或“对象定义的错误”。或者对象_global失败的'方法范围'将代码调整为" 设置rng =工作表("概述")。范围(" ReportingDetail")" 。这是代码:
Sub CleanProcesses()
Dim Processrng As Range
Set Processrng = ThisWorkbook.Names("Process").RefersToRange
If Range("ProcessesRowNum").Value <= 1 Then
Exit Sub
End If
Dim I
Range(Processrng, Range(Processrng).End(xlDown)).Name = "ProcessesRange"
ProcessesRangeIRow = Worksheets("Overview").Range("ProcessesRange").Count - 2
For I = 1 To ProcessesRangeIRow
Range(Processrng).Activate
ActiveCell.Offset(2, 0).Select
targetrow = ActiveCell.Row
Range(targetrow & ":" & targetrow).Select
Selection.Delete Shift:=xlUp
Range("A" & targetrow - 1).Select
Next I
End Sub
Sub CleanReporting()
Dim Reportingrng As Range
####**Set Reportingrng = ThisWorkbook.Names("ReportingDetail").RefersToRange
'Set Reportingrng = Worksheets("Overview").Range("ReportingDetail")**####
If Range("ReportingRowNum").Value <= 1 Then
Exit Sub
End If
Dim I
Range(Reportingrng, Range(Reportingrng).End(xlDown)).Name = "ReportingRange"
ReportingRangeIRow = Worksheets("Overview").Range("ReportingRange").Count - 2
For I = 1 To ReportingRangeIRow
Range(Reportingrng).Activate
ActiveCell.Offset(2, 0).Select
targetrow = ActiveCell.Row
Range(targetrow & ":" & targetrow).Select
Selection.Delete Shift:=xlUp
Range("A" & targetrow - 1).Select
Next I
End Sub
我已经将代码行中的哈希值###置于错误上。我似乎无法弄清楚如何通过这个?任何帮助将非常感激。提前谢谢。