简体   繁体   中英

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?

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.

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.

To avoid copying eg headers above you could code eg as follows (note the changed variable names firstDataRow and lastDataRow ):

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."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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