Solved

Fill down Formulas

Posted on 2011-09-06
9
277 Views
Last Modified: 2012-05-12
I'm trying to automatically fill down my formulas in a macro but it doesn't seem to be working.

My values start in row B9 and don't always go down to a certain row # so I want to be able to copy down the formulas in columns E9:T9 until it finds no more data in column B.

What's wrong with my code?
Dim LR As Integer
     LR = Range("B9" & Rows.Count).End(xlUp).Row
     Range("E9").AutoFill Destination:=Range("E9:T" & LR), Type:=xlFillDefault

Open in new window

0
Comment
Question by:Lawrence Salvucci
  • 4
  • 3
  • 2
9 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 250 total points
ID: 36488809
Declare LR as Long in line 1, and in line 2 remove the '9'.
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 36488956
Nope still not working. I'm now getting a "AutoFill method of Range class failed".
0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 250 total points
ID: 36489035
Try:

Range("E9:T9").AutoFill Destination:=Range("E9:T" & LR), Type:=xlFillDefault
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 36489155
Still not working. Now it's deleting all my formulas in row E9:T9 and not copying anything down.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 36489173
Does it matter that my headers are in row 8 with nothing in rows 1:7?
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 36489245
Can you step through the code and check the value of LR? It sounds like you don't have any data.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36489277
Code should be:

Dim LR As Long
     LR = Range("B" & Rows.Count).End(xlUp).Row
     Range("E9:T9").AutoFill Destination:=Range("E9:T" & LR), Type:=xlFillDefault

Open in new window


note that I removed the 9 from line 2.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36489282
The code also assumes you have data in column B for all the applicable rows.
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 36489302
Got it working. I was running the code before I had any data in column B. Working fine now. Thank you both for your help!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now