PDA

View Full Version : [SOLVED] Autofill Destination Offset



Edmond
04-17-2019, 05:57 AM
Hey Everyone!

I am experiencing some trouble with the autofill destination. I would like to offset a range (with multiple selection) but I have a run-time error.

Here is the code:



Dim rg As Range
Set rg = Union(Range("C2:C3"), Range("C28:C33"), Range("C58:C67"))

rg.AutoFill Destination:=rg.Offset(, 2) ''This line is obvisouly wrong but can't figure why...


Any clue?

Thanks a lot!

Edit:

I've come up with this solution, but would like to know if there is another way to proceed:



Dim rg As Range
Set rg = Union(Range("C2:C3"), Range("C28:C33"), Range("C58:C67"))
Set rg2 = Union(Range("C2:C3"), Range("C28:C33"), Range("C58:C67")).Resize(,c) ''only issue is that c is an integer but it still works

rg.AutoFill Destination:=rg2


Edit2:

My mistake, I looked into the property of the "AutoFill"
Destination must include source range
A resize does the trick.