Results 1 to 3 of 3

Thread: Copying a Ranges Values Only

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2004
    Location
    Right here
    Posts
    275

    Copying a Ranges Values Only

    Hi,

    I am trying to write a VBA subroutine that is activated by a button and that copies the contents of one range to another.

    For the sake of argument lets say I am trying to copy data from a range called Source_Range to a range called Destination_Range.

    The problem I am having is that the source range contains formulas in each cell, and I only want to copy the results (numbers) of those formulas to the destination range. But if I use the following code:

    VB Code:
    1. Range("Source_Range").Copy Range("Destination_Range")
    ...it just copies the formulas as well.

    If I use this code:

    VB Code:
    1. Range("Source_Range").Copy
    2.         Range("Destinaton_Range").Select
    3.             Selection.PasteSpecial Paste:=xlPasteValues
    ...it works, but it also has to select the destination range in order for it to work.

    What I really want is a way to PasteSpecial the values only but without having to actually select any of the ranges, as in the first set of code (only this also copies the formulas, which isn't what I want).

    Is there anyway to do this? Or does PasteSpecial always require that you select the range that you want to paste to? Is there an alternative to PasteSpecial that I could use?

    Thanks in advance
    -Rob

    *Edit*

    I also tried this, which I thought would work but it doesn't actually seem to do anything (it doesn't produce an error either, it just does nothing):

    VB Code:
    1. Range("Destination_Range") = Range("Source_Range")
    Why doesn't this work? I thought it would do, since it works for individual cells, but not for named ranges?!?!
    Last edited by TheRobster; Jul 13th, 2005 at 05:33 PM.
    http://www.sudsolutions.com

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Copying a Ranges Values Only

    Code:
    Range("Source_Range").Copy
    Range("Destinaton_Range").PasteSpecial Paste:=xlPasteValues
    Did you try the above?

    Are Source_Range and DEstination_Range variables or named ranges?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    Junior Member
    Join Date
    Jul 2005
    Posts
    20

    Re: Copying a Ranges Values Only

    Have you tried something like

    VB Code:
    1. Range(InCell1, InCell2).Value = Range(OutCell1, OutCell2).Value

Posting Permissions

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



Click Here to Expand Forum to Full Width