ExcelSheetImage 我想填充单元格,直到最后一行和最后一列。对于我要浏览的每个Excel工作表,列和行的数量都不同。
到目前为止,我下面的代码用于填充C列中的所有行,但无法编译
Sub populate()
Dim lastrow, lastcol As Long
lastrow = Sheet1.Cells(Rows.Count, 2).End(xlUp).Row + 1 'finds last row in B
Range(lastrow, 3).Formula = "=sum(A2:B2)" 'populates cells in C with formula
until last row
End Sub
答案 0 :(得分:0)
Range
需要两个单元格的开始和结束或一个字符串。 Cells
行和列
Sub populate()
Dim lastrow, lastcol As Long
lastrow = Sheet1.Cells(Sheet1.Rows.Count, 2).End(xlUp).Row + 1 'finds last row in B
Sheet1.Range("C2",Sheet1.Cells(lastrow, 3).Formula = "=sum(A2:B2)" 'populates cells in C with formula
End Sub