Beginner macro user - Autofill macro required

gtaras01

New Member
Joined
Jul 21, 2011
Messages
4
Hi everyone,

I am using Excel 2007.
I don't have any programming experience and I have managed to create a macro that will do autofill once (with numerical increments of one). But now I need a macro that will:

Autofill series in increments of one
Work in a single column - with unknown number of rows
Will recommence the series from one - with an autofill from every time there is a value of '1' (however the '1' are at different distances apart

I found a code that has been fantastic for autofilling based on above value and wanted to adapt it for autofilling, but I really have no idea how to do it apart from autofilling from each instance of '1' in the column manually (potentially 100's of times).

The code I found for the fill above was by by Dave Peterson 2004-01-06
'fill blank cells in column with value above
From - http://www.contextures.com/xlDataEntry02.html


Code:
Sub FillColBlanks()
'[COLOR=Red]by Dave Peterson  2004-01-06[/COLOR]
'fill blank cells in column with value above
'http://www.contextures.com/xlDataEntry02.html
Dim wks As Worksheet
Dim rng As Range
Dim LastRow As Long
Dim col As Long

Set wks = ActiveSheet
With wks
   col = ActiveCell.Column
   'or
   'col = .range("b1").column

   Set rng = .UsedRange  'try to reset the lastcell
   LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
   Set rng = Nothing
   On Error Resume Next
   Set rng = .Range(.Cells(2, col), .Cells(LastRow, col)) _
                  .Cells.SpecialCells(xlCellTypeBlanks)
   On Error GoTo 0

   If rng Is Nothing Then
       MsgBox "No blanks found"
       Exit Sub
   Else
       rng.FormulaR1C1 = "=R[-1]C"
   End If

   'replace formulas with values
   With .Cells(1, col).EntireColumn
       .Value = .Value
   End With

End With

End Sub
I thought this macro would be useful to try and adapt, changing the 'repeat above' values to 'autofill' when row value = 1 with autofill increments of 1.

Can anyone assist me to work out how I might do this?

Thanks in advance
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
The raw data would look like column A, and after running such as macro the result would be Column B - without using the fill series button to fill every value with '1':


-- removed inline image ---
 
Upvote 0
<table style="width: 114px; height: 470px;" border="0" cellpadding="0" cellspacing="0"><col style="mso-width-source:userset;mso-width-alt:4169;width:86pt" width="114"> <tbody><tr style="height:15.0pt" height="20"> <td style="height:15.0pt;width:86pt" height="20" width="114">To clarify, I need a Macro to autofill between the '1's:</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt" align="right" height="20">1</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">2</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">3</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt" align="right" height="20">1</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">2</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt" align="right" height="20">1</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt" align="right" height="20">1</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">2</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">3</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">4</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">5</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">6</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">7</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl63" style="height:15.0pt" align="right" height="20">1</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">2</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">3</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">4</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">5</td> </tr> <tr style="height:15.0pt" height="20"> <td style="height:15.0pt" align="right" height="20">6</td> </tr> </tbody></table>
 
Upvote 0
I have worked out how to do it without using a macro since I'm not sure how to write one - for anyone who may find the solution to this problem useful:

Fill Series Blanks in increments of one Via a Formula

Quick and easy way to fill those blanks with the value of the cell above (plus one).
Select all the data in a column, then [Ctrl+G] then [special] then [blanks] and click OK. This will now have selected only the empty cell within the list.
Now push the Equals (=) key, then the Up arrow, then enter +1 (formula) and finally, holding down the Ctrl key, push Enter.

Problem solved!
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

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