我写了一个宏,它可以计算A和B两列中的行数,如果A包含的行数比B多(真的是 "B:AK"),那么我就会自动填充B:AK到A行,但是如果不知何故自动填充失灵或有人搞乱了工作表,IF b>a我就会清除B:AK到A列的最后一行。
Dim lSKUrow As Long
Dim lVOLrow As Long
Dim ix As Integer
Dim iy As Integer
Dim rngFormula As Range
With Workbooks("Raw Data Production").Worksheets("Raw Data")
lSKUrow = .Range("A" & Rows.Count).End(xlUp).Row
lVOLrow = .Range("B" & Rows.Count).End(xlUp).Row
Set rngFormula = .Range("B" & ix & ":AK" & ix)
ix = lSKUrow
iy = lVOLrow
If x > y Then
Workbooks("Raw Data Production").Worksheets("Raw Data").rngFormula.AutoFill Destination:=ActiveWorkbook.ActiveSheet.Range("B" & ix & ":AK" & ix)
Else
If y > x Then
ActiveWorkbook.ActiveSheet.Range("B" & ix + 1 & ":AK" & ix + 1).End(xlDown).Clear
End If
End If
End With
End Sub
现在我一直收到错误提示,我不知道为什么.他们突出显示了这部分代码 "Set rngFormula = .Range("B" & ix & ":AK" & ix) "错误提示说 "运行时错误1004,应用程序或对象定义错误......"。
有没有更好的方法来写这部分代码?
你还没有定义 ix
在宏点击之前 Set rngFormula
行。我也没有看到 x
或 y
在任何地方定义,你在if语句中使用它们。