简体   繁体   English

VBA Filldown 在只有一行数据时复制 header

[英]VBA Filldown copies the header when there is only a row of data

as the title says, the filldown works fine in VBA when I have more than 2 rows of data, but when I only have one row, it copies the header, why is it doing this?正如标题所说,当我有超过 2 行数据时,填充在 VBA 中工作正常,但是当我只有一行时,它会复制 header,为什么要这样做?

PASsht.Range("I" & LastRow1 & ":I" & AftLastRow).FillDown

LastRow1 is the first row where the data is, AftLastRow is the last row where the data is. LastRow1 是数据所在的第一行,AftLastRow 是数据所在的最后一行。

Thanks in advance.提前致谢。

Though there's no hint in MS Help FillDown method *), in case of one single data row (ie the first data row equals the last data row), the FillDown method will grab the contents of above and fill it to that cell.虽然 MS Help FillDown 方法*) 中没有提示,但在单个数据行的情况下(即第一个数据行等于最后一个数据行),FillDown 方法将抓取上面的内容并将其填充到该单元格。

To avoid copying eg headers above you could code eg as follows (note the changed variable names firstDataRow and lastDataRow ):为了避免复制例如上面的标题,您可以编写如下代码(注意更改的变量名称firstDataRowlastDataRow ):

If firstDataRow <> lastDataRow Then PASsht.Range("I" & firstDataRow & ":I" & lastDataRow).FillDown

*) As mentioned above, help states only: *)如上所述,帮助仅说明:

"Fills down from the top cell or cells in the specified range to the bottom of the range. The contents and formatting of the cell or cells in the top row of a range are copied into the rest of the rows in the range." “从指定范围内的顶部单元格或单元格向下填充到范围的底部。范围顶行中的一个或多个单元格的内容和格式被复制到该范围内行的 rest 中。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM