Forum Discussion
Creating a formula to autofill a range of cells based on input
Hello tazewellj,
Enter this formula into cell A2 and use cell B1 to input your number:
=IF(ROW(A2)-1>$B$1,"",ROW(A2)-1)
Then copy the formula down as necessary.
Hope this helps!
PReagan
- mayuranaOct 24, 2019Copper Contributor
Hello PReagan
Thanks for the earlier response .. this was also something i was looking for but i had an additional requirement.
In the response it was mentioned that we have to drag the formula down to the required number of cells in column A.
However can it be possible that say N number of Rows automatically fill based on the value of N entered in B2 e.g. if a person enters 512 in B2, A2:A513 all gets a number starting from 1 and incremented downwards .. ( without have to drag the formula all the way to A513 ) the number N could be any value (no max limits)
- PReaganOct 24, 2019Bronze Contributor
This would require VBA if you wish to fill N number of cells with the formula.
Alternatively, as @Peter Bartholomew suggested, you may "take your existing formula and fill it down beyond your range of interest;" (for example cell A1048576) " a slight modification would return "" for values you do not require." The downside to this, however, is that this would slow down Excel.
- PeterBartholomew1Oct 24, 2019Silver Contributor
I think your options are
- Take your existing formula and fill it down beyond your range of interest; a slight modification would return "" for values you do not require.
- Buy a copy of Office 365 and set it to insider or monthly update so that you can use the dynamic arrays and the SEQUENCE function
- Write a VBA macro to rewrite the values when N changes in cell B2
- Use PowerQuery to write the sequence when the data is refreshed
- mayuranaOct 24, 2019Copper Contributor
Thanks PeterBartholomew1 for a quick response, i was looking for a more generic solution which would not be dependent on the office version or VBA.
I dont think this is easily doable, please let me know otherwise
- tazewelljAug 08, 2019Copper Contributor
PReagan I'm not sure the ROW function will achieve this. The ROW function returns the value of the row. The formula you provided will always return a value of 1 no matter what.
- PReaganAug 08, 2019Bronze ContributorThe row function Row(A2)-1 will always be equal to 1 for cell A2 unless B1=0. When you copy the formula down to cell A3, the function becomes Row(A3)-1=2. Copied down again to cell A4 the formula becomes Row(A4)-1=3. The formula continues to add one to the previous total until it has reached a value greater than B1 at which point “” will be returned.
Unless I am misunderstanding your problem, this should return your desired result.
- tazewelljAug 08, 2019Copper Contributor
PReagan thanks for your quick response. Unfortunately this always returns a value of 1 in cell A2. This is a great start, but I am trying to create a formula that will fill a range of cells. For instance, if I the value 3 in cell B1, I would like cells to filled as followed:
A2 1
A3 2
A4 3My goal is to have a numbered rows based upon user input.
Thanks,
tazewellj