Solved

Fill down Formulas

Posted on 2011-09-06
9
294 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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
 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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