Consulting

Results 1 to 3 of 3

Thread: Creating a macro to copy formulas

  1. #1

    Creating a macro to copy formulas

    hi all, looking for some help.....not too clued up on macros!.....

    I want a macro to copy this exact formula (as shown in the txt bar, not changing the cell references as it does it) across to the 7 cells directly to the right of the current selected cell.

    not sure how to make it copy the formula and paste it as it stands, rather than changing it with the cell references within it


    iv only got this so far....but it doesnt work :s




    Sub AutoShape11_Click()

    ActiveCell.Select
    ActiveCell.Copy


    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
    False
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
    False
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
    False
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
    False
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
    False
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
    False
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
    False
    End Sub

  2. #2
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    Yeah...you're way off. Is it important that the formula is preserved as you copy over, or do you just want the value of the active cell?

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Sub CopyFormula()
    Dim fmla As String
    fmla = ActiveCell.Formula
    ActiveCell.Offset(5, 4).Formula = fmla
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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