Dim lastrow As Long -将多个值添加到数据底部的行



我已经创建了一个电子表格来格式化一些原始数据,一旦找到最后一行,我想在F列中插入下面的内容。

TOTALS
YTD Dividends
(row in between)
YTD Interest
(row in between)
YTD Gain/Loss

使用下面来获得总计,但无法弄清楚如何在列f中添加下面的附加标题。这是不可能的,因为我使用最后一行?每个电子表格的行数会有所不同,所以我需要找到末尾并插入值。

'...
End With
Dim lastrow As Long
lastrow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row + 2
With Selection
ActiveSheet.Cells(lastrow, "F").Value = "TOTALS"
End With
End Sub

你可以这样做:


'...
End With
'offset 2 rows down and 2 columns to the right
With ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Offset(2, 2)
.Value = "TOTALS"
.Offset(1).Value = "YTD Dividends"
.Offset(3).Value = "YTD Interest"
.Offset(5).Value = "YTD Gain/Loss"
End With

End Sub

最新更新