How to auto-fill a column with consecutive numbers using VBA

Mr2017

Well-known Member
Joined
Nov 28, 2016
Messages
644
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

I have data in columns A - C and the number 1 in cell D1.

Does anyone know how I can drag the numbers from cell D1 to the rest of the column D (up to the last row of the data in column A) in consecutive order?

So my data would initially look like this:

ADG
1​
BEH
CFI


However, I would like it to look like the table below (NB - the number of rows will vary, so the drag would have to be dynamic rather than fixed). TIA.

ADG
1​
BEH
2​
CFI
3​
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
One way
VBA Code:
Range("D1").AutoFill Range("D1:D" & Range("A" & Rows.Count).End(xlUp).Row), xlFillSeries
 
Upvote 0
Another way ..

VBA Code:
Range("D1:D" & Range("A" & Rows.Count).End(xlUp).Row).DataSeries , xlLinear
 
Upvote 0
You're welcome. I'm not suggesting that it is a better way, just a different way. :)
 
Upvote 0
hi, guys nice code but what if there is no number in d1 it 's empty how is the code starts number 1
 
Upvote 0
How is Excel supposed to know what number you want to start with if you don't input it. (Either manually or by code)?
 
Upvote 0
hi, mark but i think some codes do that if specify the number rows by function do that if cell is filling then the next cell give the number without i write manually i'm not sure it just guess
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top