Trying to modify this 'auto-fill down to the next empty cell' macro to auto-fill sequential numbers instead

funguy

New Member
Joined
Feb 7, 2012
Messages
24
Hi all, I've attached a worksheet with the macro already installed that will auto-fill cell values down through empty cells to the next cell containing data (and so on and so on).. It works great! BUT, I'm now trying to modify it to make it fill empty spaces with sequential numbers. Any help would be appreciated. - thank you

(could not figure out how to attach xlsm file - but added it to the Hightail link below - thanks )

https://www.yousendit.com/download/bXBZeFlhZy80b0JvZE1UQw
 
Last edited:

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

svendiamond

Well-known Member
Joined
Jun 13, 2014
Messages
1,498
Office Version
  1. 365
Platform
  1. Windows
Use this code to fill column B the way you did in your example.

Code:
Sub FillNumbers()


Dim loopCounter As Integer
Dim lastRow As Long
    lastRow = Range("A" & Rows.Count).End(xlUp).Offset(1).Row - 1
    
For loopCounter = 2 To lastRow Step 1


    If Cells(loopCounter, 1) = 1 Then
        Cells(loopCounter, 2).Value = 1
    Else
        Cells(loopCounter, 2).Value = Cells(loopCounter, 2).Offset(-1) + 1
    End If


Next




End Sub
 

funguy

New Member
Joined
Feb 7, 2012
Messages
24
Hi Svendiamond , Months later... but I'm revisiting this one..

Now I'm trying to do this same thing , but not all values begin with "1"... Do you know how this might be possible if the beginning numerical values are varying ? (i.e. - not always strting with "1". So, find current value, and then count upwards sequentially from there..)

much thanks , A
 

svendiamond

Well-known Member
Joined
Jun 13, 2014
Messages
1,498
Office Version
  1. 365
Platform
  1. Windows
Hmm, well your shared file is expired so I can't download it again. I don't remember what your sheet looks like. Best way to show me what your sheet looks like is to install the Mr Excel HTML Maker (it will also make future questions easier to solve) from this link: http://www.mrexcel.com/forum/about-board/508133-attachments.html#post2545970

But if you can't install the add-in, I guess just upload your file again. Or explain in more detail. I'm sure there is an easy solution for your problem.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,528
Messages
5,625,337
Members
416,096
Latest member
forevans

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
Top