简体   繁体   English

如何仅在excel VBA中粘贴VALUES?

[英]How to paste VALUES ONLY in excel VBA?

So I need to paste the values only of a range of data into the sheet "MasterList".所以我只需要将一系列数据的值粘贴到工作表“MasterList”中。 I was looking for ways to do this and found this:我正在寻找方法来做到这一点,并发现了这一点:

.PasteSpecial Paste:=xlPasteValues

How should I go about changing my code so that I can use the .PasteSpecial Paste:=xlPasteValues function?我应该如何更改我的代码以便我可以使用 .PasteSpecial Paste:=xlPasteValues 函数? I'm thinking I need two lines of code to accomplish this but I can't figure out the syntax...我想我需要两行代码来完成这个,但我无法弄清楚语法......

Dim Lastrow As Integer

Lastrow = Cells(15, 3).Value + 3

Dim Copyrange As String

Startrow = 3
Let Copyrange = "I" & Startrow & ":" & "K" & Lastrow
Range(Copyrange).Select
Selection.Copy

Sheets.Add.Name = "MasterList"
**ActiveSheet.Paste Destination:=Range("A1")**
ActiveSheet.Move

You should avoid using select but also avoid the clipboard as that is slow:您应该避免使用 select 但也要避免使用剪贴板,因为它很慢:

With ActiveSheet 'should put the actual sheet here
    Dim Lastrow As Long
    Lastrow = .Cells(15, 3).Value + 3
    
    Dim startrow As Long
    startrow = 3
    
    Dim Copyrange As String
    Copyrange = "I" & startrow & ":" & "K" & Lastrow
    
    Dim rng As Range
    Set rng = .Range(Copyrange)
    
    Dim mstlt As Worksheet
    Set mstlt = Worksheets.Add
    
    mstlt.Name = "MasterList"
    
    mstlt.Range("A1").Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value
End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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