Solved

Excel Auto Fill Rows with a formula based on length of previous column

Posted on 2013-06-20
6
653 Views
Last Modified: 2013-06-20
Hello Experts,

I have an excel output created by a database.  What I need to do is create a macro that will auto fill in a formula down a column to the length of the previous column.

For example:

N2 - N205 (can be varied length, exp. N2 - N602)  Then place a formula in column O2 - O205

Thanks!
0
Comment
Question by:CompTech810
  • 3
  • 3
6 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 39262663
Something like:
Range("O2:O" & Cells(rows.count, "N").end(xlup).row).Formula = "=your_formula_here"

Open in new window

0
 
LVL 2

Author Comment

by:CompTech810
ID: 39262705
I tried your code and I get this error: Application-defined or object-defined error.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 39262795
What did you put in for your formula?
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 2

Author Comment

by:CompTech810
ID: 39262825
Range("O2:O" & Cells(Rows.Count, "N").End(xlUp).Row).Formula = "=IF(COUNTIF($N2:N$2,N2)>1,"",N2)"

Open in new window

0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 150 total points
ID: 39262934
You need to double the quotes for any quotes within the formula string:

Range("O2:O" & Cells(Rows.Count, "N").End(xlUp).Row).Formula = "=IF(COUNTIF($N2:N$2,N2)>1,"""",N2)"

Open in new window

0
 
LVL 2

Author Closing Comment

by:CompTech810
ID: 39263255
Awesome, that worked!  Thanks!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Outlook 2012 VBA: Object missing 14 33
Excel VBA 10 40
Excel error  #DIV/0! 7 18
EXCEL formual to calculate Quarter 6 37
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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