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
319 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
4 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 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 45

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

943 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now