Solved

Excel VBA to copy formulas

Posted on 2015-01-22
5
64 Views
Last Modified: 2015-01-22
Hello,

i need help with a VBA code.

where when i run it in activesheet.  it will look for all cells in second row and if formula is found then copy and paste the formula to the last row of each column that have formula in second row.

thanks.
0
Comment
Question by:Flora
[X]
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
  • 2
  • 2
5 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40564052
I wouldn't use VBA code; it's redundant. If you use a Table (Ctrl+L or Insert - Tables - Table), then formulas can auto-repeat downwards automatically. See https://support.office.com/en-gb/article/Create-an-Excel-table-33d08e18-fa0f-40fe-8af3-5683b034ec42 for more details.
0
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40564053
if VBA

Sub Macro()

For Each c In Range(Range("A2"), Cells(2, Cells.Columns.Count).End(xlToLeft))
    If c.HasFormula Then
        Cells(Cells.Rows.Count, c.Column).End(xlUp).Offset(1).FormulaR1C1 = c.FormulaR1C1
    End If
Next
End Sub

Open in new window

Regards
0
 
LVL 6

Author Comment

by:Flora
ID: 40564105
Rgonzo1971

the above code works.

but it has one issue.

it goes one below the last row.   for example if my formulas end at row 10 then it goes one below. how do i stop it?
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 40564239
then change to

Sub Macro()

For Each c In Range(Range("A2"), Cells(2, Cells.Columns.Count).End(xlToLeft))
    If c.HasFormula Then
        Cells(Cells.Rows.Count, c.Column).End(xlUp).FormulaR1C1 = c.FormulaR1C1
    End If
Next
End Sub

Open in new window

0
 
LVL 6

Author Comment

by:Flora
ID: 40564247
thanks Rgonzo1971
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

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…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

732 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