VBA – 最后一行数字中断为参考单元空,但不是

我有一个macros的一部分,但是这是第一个整理表单之前运行

要确定列和表整理我试图find最后一个空值,并创build一个列和表范围作为variables在我的模块中使用。 然而,无论我select单元格C4还是C5,或者在R1C1风格中引用它们,都会发生断裂,就好像单元格是空的,但它们不是。

它打破了

LRow = ws.Cells(Rows.Count, C5).End(xlUp).Row 

不确定如何让它继续下去。

 Sub Tidy() ' ' Tidy Macro ' ' Dim table_1 As Long Dim table_2 As Long Dim col_len, table_len As Range Dim LRow As Long Dim ws As Worksheet Set ws = ThisWorkbook.ActiveSheet LRow = ws.Cells(Rows.Count, C5).End(xlUp).Row Set col_len = ws.Range("C4:C" & Cells(LRow).Address(False, False)) Set table_len = ws.Range("A4:F" & Cells(LRow).Address(False, False)) table_2 = Worksheets("DumpSheet").Cells(Row.Count, R5C10).End(xlUp).Row Range("A5").Select ActiveCell.FormulaR1C1 = "=R1C1" Range("A5").Select Selection.AutoFill Destination:=Range("A5:A" & col_len) Range(table_len).Select Selection.Copy Range("H5").Select ActiveSheet.Paste Range("B5").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "=R[-4]C" Range("B5").Select ActiveCell.FormulaR1C1 = "=R1C2" Range("B5").Select Selection.AutoFill Destination:=Range("B5:B" & col_len) Range("B5:B" & table_1).Select Range("I5").Select ActiveCell.FormulaR1C1 = "=R1C9" Range("I5").Select Selection.AutoFill Destination:=Range("I5:I29") Range("I5:I" & table_2).Select End Sub 

C5正在被视为一个尚未分配的variables。 这不是一个单元格的参考。 你正在寻找更像是的东西:

 LRow = ws.Cells(ws.Rows.Count, 3).End(xlUp).Row