Consulting

Results 1 to 6 of 6

Thread: Copying Formulas

  1. #1
    VBAX Regular Erays's Avatar
    Joined
    Mar 2005
    Posts
    73
    Location

    Copying Formulas

    I know that there has to be a way, but I don't know how, I would like to copy multiple formulas and insert them in a different place on the worksheet or on another sheet. when I copy the cells and paste special the formulas it paste the formulas but changes the value of the formula.

  2. #2
    VBAX Contributor Glaswegian's Avatar
    Joined
    Sep 2004
    Location
    Glasgow, Scotland
    Posts
    196
    Location
    Hi Erays

    Sounds like you may need to make your formula references absolute. Say you have this fomula in cell C1

    =SUM(A1:B1)
    Click on A1 in the formula bar - now press F4. The "A" will now be surrounded with dollar signs and should look like this

    =SUM($A$1:B1)
    You've now made the formula reference to cell A1 absolute. When you copy and paste it will remain as A1. Do the same for B1.

    If you just wanted the column reference to remain absolute then it would be

    =SUM($A1:B1)
    and for rows it would be

    =SUM(A$1:B1).
    Does this help?

    Regards
    Iain - XL2010 on Windows 7

  3. #3
    VBAX Regular Erays's Avatar
    Joined
    Mar 2005
    Posts
    73
    Location
    If the formulas are already on the page will I have to change each one and then copy them

  4. #4
    VBAX Contributor Glaswegian's Avatar
    Joined
    Sep 2004
    Location
    Glasgow, Scotland
    Posts
    196
    Location
    Hi

    I thought this code might work

    Sub ChangeCellRefs()
    Dim myRng As Range
    Dim c As Range
    Set myRng = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas)
    For Each c In myRng
    Application.ConvertFormula Formula:=c.Formula, fromReferenceStyle:=xlA1, ToAbsolute:=xlAbsolute
    Next
    End Sub

    but it's not - and I can't figure out why .

    See if it works for you - I'll keep trying.

    Regards
    Iain - XL2010 on Windows 7

  5. #5
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I'm not over-familiar with this but it appears to work this way ...

    c.Formula = Application.ConvertFormula(Formula:=c.Formula, fromReferenceStyle:=xlA1, toReferenceStyle:=xlA1, ToAbsolute:=xlAbsolute)
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  6. #6
    VBAX Contributor Glaswegian's Avatar
    Joined
    Sep 2004
    Location
    Glasgow, Scotland
    Posts
    196
    Location
    Nice one Tony - I was not really familiar with that myself so it was a bit of a learning curve!

    Regards
    Iain - XL2010 on Windows 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •