VBA – Autofill with a Macro
Autofill in VBA
Take control of Autofill using vba with this simple macro code example. It takes the data from the range A1:A2 and autifills it to A20. This can be modified to autofill any way you would like using a little macro tweaking.
Selection1 is the range with the data to autofill.
Selection2 is the entire range to autofill, this includes the first range plus the blank spaces to autofill.
Public Sub MyAutoFill()
'Declare range Variables
Dim selection1 As Range
Dim selection2 As Range
'Set range variables = their respective ranges
Set selection1 = Sheet1.Range("A1:A2")
Set selection2 = Sheet1.Range("A1:A20")
Here’s the before and after picture
VBA Coding Made Easy
Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!