Solved

Excel VBA to copy formulas

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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 …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

724 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