?
Solved

In Excel VBA, how can I do a copy and a pastespecial WITHOUT using the Windows copy buffer?

Posted on 2013-05-22
4
Medium Priority
?
327 Views
Last Modified: 2013-05-22
My problem is that when I use code that does a copy and then a PasteSpecial in Excel, while that code is running (ie: in a loop), I can't use the copy buffer in my system for anything else as it gets replaced with the data from the Excel copy.  This happens when I use code like this:

With Worksheets("Sheet1")
    .Range("C1:C5").Copy
    .Range("D1:D5").PasteSpecial _
        Paste:=xlPasteValues
End With

Open in new window


I have no problem if I do a single statement copy in Excel VBA with code like this:

With Worksheets("Sheet1")
    call .Range("C1:C5").Copy(.Range("D1:D5"))
End With

Open in new window


But doing it that way, I can't do a paste special which I need so that I can replace the formulas with values.

How can I get around this problem?
0
Comment
Question by:cashonly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 2000 total points
ID: 39187966
Try

With Worksheets("Sheet1")
    .Range("D1:D5").value = .Range("C1:C5").value
End With
0
 
LVL 20

Expert Comment

by:dsacker
ID: 39187968
Since  you're placing the values in column D from the formulas in column C, you could simply do this:
    Dim row As Integer
    For row = 1 To 5
        Cells(row, 4).Value = Cells(row, 3).Text
    Next row

Open in new window

0
 
LVL 46

Expert Comment

by:aikimark
ID: 39189705
The ssaqibh comment http:#a39187966 is the right way to do it.
0
 

Author Closing Comment

by:cashonly
ID: 39189721
Worked great!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question