Consulting

Results 1 to 5 of 5

Thread: Solved: Alter code to only copy values without formulas

  1. #1
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location

    Solved: Alter code to only copy values without formulas

    I am using this code to copy date from one work book to another, but it is also copying formulas from the selected cells.

    What do I have to do to alter the code to stop it form also copying formulas.

    I tried
    [VBA]Set RngCopy.Values[/VBA]
    But this was bugging out.


    [VBA]Sub Copy()
    Dim RngCopy As Range
    Dim RngPaste As Range

    Set RngCopy = Workbooks("Results.xls").Sheets("Final Results").Range("A1:I42")
    Set RngPaste = Workbooks("Results Email.xls").Sheets("Results Sheet").Range("A1:I42")
    RngCopy.Copy RngPaste
    RngCopy.Copy RngPaste
    End Sub
    [/VBA]

    Any thoughts?

    Thanks very much

  2. #2
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    Use .PasteSpecial (xlValues)

  3. #3
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location
    I tried changing the RngPaste to RngpasteSpecial but it is still copying the formulas?

    Is that what you were refering to do?

    Thanks

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    I see what you were trying to do with the 2nd RngPaste, if you are not going to use .PasteSpecial then what you really needed was:[VBA]Sub Copy()
    Dim RngCopy As Range
    Dim RngPaste As Range

    Set RngCopy = Workbooks("Results.xls").Sheets("Final Results").Range("A1:I42")
    Set RngPaste = Workbooks("Results Email.xls").Sheets("Results Sheet").Range("A1:I42")
    RngCopy.Copy RngPaste
    RngPaste = RngPaste.Value
    End Sub
    [/VBA]
    Quote Originally Posted by Barryj
    I am using this code to copy date from one work book to another, but it is also copying formulas from the selected cells.

    What do I have to do to alter the code to stop it form also copying formulas.

    I tried
    [vba]Set RngCopy.Values[/vba]
    But this was bugging out.


    [vba]Sub Copy()
    Dim RngCopy As Range
    Dim RngPaste As Range

    Set RngCopy = Workbooks("Results.xls").Sheets("Final Results").Range("A1:I42")
    Set RngPaste = Workbooks("Results Email.xls").Sheets("Results Sheet").Range("A1:I42")
    RngCopy.Copy RngPaste
    RngCopy.Copy RngPaste
    End Sub
    [/vba]

    Any thoughts?

    Thanks very much
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location
    That has done the trick, thanks very much Simon, have marked this as solved.

    Thanks again for yor assistance.

Posting Permissions

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