AutoFill Horizontally

Hanz77

Board Regular
Joined
Sep 21, 2006
Messages
87
I'm trying to write a VB Script that will autofill horizontally. For example, my data range is G2:Y2. I am trying to get the script to autofill a formula between cells G1 and Y1. But the script needs to be flexible enough to autofill through column AA if there is data between cells G2 and AA2.

I frequently use code that does this vertically, but I have not been able to do this horizontally. For reference, following is my code to do this vertically.

Range("B2").AutoFill Destination:=Range("B2:B" & Range("A65536").End(xlUp).Row)

Any assistance is appreciated.
 

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,649
Try this:

Cells(1, 2).AutoFill Destination:=Range(Cells(1, 2), Cells(1, Cells(2, Columns.count).End(xlToLeft).column))
 

Hanz77

Board Regular
Joined
Sep 21, 2006
Messages
87
Exactly what I was trying to figure out...simple and efficient.

Thanks!
 

Forum statistics

Threads
1,085,331
Messages
5,383,014
Members
401,812
Latest member
topherj09

Some videos you may like

This Week's Hot Topics

Top