Solved

Excel VBA to copy formulas

Posted on 2015-01-22
5
60 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 49

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 49

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

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.

Question has a verified solution.

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

Suggested Solutions

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

786 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