I have a Excel Sheet that contains column headers in Row 1 and different formulas in Row 2.
To dynamically fill in the formulas based on the tables length I created a macro that extends the formulas to the last row using the “FillDown” function. However, I noticed that whenever my table is of length 1 (Meaning, Only Row 2 holds values) the FillDown function won’t behave as expected as it will overwrite my formulas in Row 2 with the contents of Row 1 (the headers).
I then started to simplify my macro to the bare minimum and the behaviour still remains. Whenever you use a Sheet1 that has a arbitrary String in Row 1, and a formula in Row 2 below. The following macro will overwrite Row 2 with the contents of Row 1, despite the fact that Row 1 is never referenced in the macro.
Sub asdf()
col = 1
Set Sheet = ThisWorkbook.Sheets("Sheet1")
Sheet.Range(Sheet.Cells(2, col), Sheet.Cells(2, col)).FillDown
End Sub
I expected that the macro would either
- do nothing, since Row 2 is already filled with its contents, and the FillDown only involves one cell.
- re-write the contents of Row 2 into Row 2, having practically no effect.
Has anyone an idea why this would happen?
(Microsoft® Excel® for Microsoft 365 MSO (Version 2308 Build 16.0.16731.20542) 32-bit )
Daniel Wullschleger is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.