Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2013-06-20
6
662 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
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…

808 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