Solved: Code Error when filling Dynamic Range

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

FLOVETT

Felton
Thread Starter
Joined
Sep 17, 2007
Messages
79
I am doing a VLOOKUP and only want to fill to a certain range - The number of blank rows appearing in column "d" as the number of rows will always vary. I have tried the following code and the vlookup places the first value in cell e2, but it stops at the Selection.Autofill line. I am getting a Run-time error Autofill method of Range class failed. Here is my code. I am using the t to count the number of rows.
Code:
 Sub test_autofill()
Dim t As Long
t = Cells(Rows.Count, "d").End(xlUp).Row
Range("e2").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],catcode.xls!CVA_PERCENT,2,0)"
    Selection.AutoFill Destination:=Range("e2" & t), Type:=xlFillDefault
    Range("e2" & t).Select
        MsgBox "please remove OT services for all customers except EQP & GSA"

End Sub
 
Joined
Sep 4, 2003
Messages
4,916
Trying using the line below instead.

Code:
Selection.AutoFill Destination:=Range("E2:E" & t)
Rollin
 

FLOVETT

Felton
Thread Starter
Joined
Sep 17, 2007
Messages
79
Thanks,

I had a little trouble at first, but it works perfectly. I will have to ammend a lot of my code using this structure. I was filling in lots of extra rows and then deleting them.. Thanks
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top