简体   繁体   中英

How to Autofill cells up to a certain row based on the value in a different cell?

So I have a cell (let's say C3) and I have a column in A.

Let's say that the formula I want to fill for the cells in column A is A2 = A1 + 1 and so forth. I have the number 30 in C3 .

I want excel to fill exactly 30 cells down column A using that previous formula (A2 = A1 + 1) . If I change the number in C3 to 50 , then excel will automatically add 20 more rows in column A following the same pattern.

If I change the number in C3 to 10 , excel will automatically delete the rows until the first 10 rows remain.

EDIT TO ADD : OK so I guess I have to use macros. Anyone suggest the VBA code for this?

You can avoid VBA if you know a maximum possible number of rows. Use the following formula in A2 and apply it downward until you've applied through the maximum number of columns.

=IF(ROW()<=$C$3,A1+1,"")

So in reality, you still have a formula in these cells, but you won't see any output until they are supposed to be seen. It's a work-around.

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