Solved

Excel VBA to copy formulas

Posted on 2015-01-22
5
58 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
  • 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 48

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 5

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 48

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 5

Author Comment

by:Flora
ID: 40564247
thanks Rgonzo1971
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
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 …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

747 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

9 Experts available now in Live!

Get 1:1 Help Now