简体   繁体   中英

Copy and Special Paste, Values with VBA

The code I have so far seems to be working. The only issue is that I seem to be copying the array formulas instead of just the value of the array formula. Is there a way to have my existing code paste special (just values) or do I need a new method entirely?

Dim s1 As Excel.Worksheet
Dim destsh As Excel.Worksheet
Dim iLastCelldestsh As Excel.Range
Dim iLastRowS1 As Long

Set s1 = Sheets("RAW - Greenphire")
Set destsh = Sheets("RAW - Concatenated")

'get last row of Q in RAW - Greenphire
    iLastRowS1 = s1.Cells(s1.Rows.Count, "Q").End(xlUp).Row
'get last AVAILABLE cell to paste into
    Set iLastCelldestsh = destsh.Cells(destsh.Rows.Count, "A").End(xlUp).Offset(1, 0)
'copy into RAW - Concatenated
    s1.Range("Q2", s1.Cells(iLastRowS1, "Q")).Copy iLastCelldestsh

Transfer values only without the clipboard.

with s1.Range("Q2", s1.Cells(s1.Rows.Count, "Q").End(xlUp))
   destsh.Cells(destsh.Rows.Count, "A").End(xlUp).Offset(1, 0).resize(.rows.count, .columns.count) = .value
end with

You may use PasteSpecial to paste the values only like below...

s1.Range("Q2", s1.Cells(iLastRowS1, "Q")).Copy
iLastCelldestsh.PasteSpecial xlPasteValues

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM