Autofill with Column as a variable

L

LuisE

I want to autofill a range of cells from row 3 to 9 in a given column just
like this

Range("B3").Select
Selection.AutoFill Destination:=Range("B3:B9")

When I use a variable the autofill returns an "Autofill method of range
class failed" error. Need help please

Cells(3, LastCol ).Select
Selection.AutoFill Destination:=Range(Cells(3, LastCol), Cells(9, LastCol ))

Thanks in adavance
 
G

Gary Keramidas

i usually do something like this:

Sub test()
Dim lastcol As Long
lastcol = 4
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
With ws
.Cells(3, lastcol).AutoFill Destination:=.Range(.Cells(3, lastcol),
_
.Cells(9, lastcol))
End With
End Sub
 
G

Gary Keramidas

wordwrap!

Sub test()
Dim lastcol As Long
lastcol = 4
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
With ws
.Cells(3, lastcol).AutoFill Destination:=.Range(.Cells(3, lastcol),_
.Cells(9, lastcol))
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top