Results 1 to 3 of 3

Thread: Copying a Ranges Values Only

Threaded View

  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

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