gpt4 book ai didi

vba - Excel VBA - 粘贴为值

转载 作者:行者123 更新时间:2023-12-04 21:16:27 25 4
gpt4 key购买 nike

我正在尝试制作一个将信息从一张纸复制到另一张纸的功能,但我正在努力将粘贴作为值功能。你知道为什么它不工作吗?

Sub Copy_Data()
Dim Src As Worksheet, Dst As Worksheet
Dim LastRow As Long, r As Range
Dim CopyRange As Range
'Change these to the correct sheet names
Set Src = Sheets("Sheet1")
Set Dst = Sheets("Sheet2")
LastRow = Src.Cells(Cells.Rows.Count, "A").End(xlUp).Row

For Each r In Src.Range("A2:A" & LastRow)
If (Month(r.Value) = "2" And Year(r.Value) = "1902") Then
If CopyRange Is Nothing Then
Set CopyRange = r.EntireRow
Else
Set CopyRange = Union(CopyRange, r.EntireRow)
End If
End If
Next r

If Not CopyRange Is Nothing Then
CopyRange.Copy Dst.Range("A1").PasteSpecial(xlPasteValues)
End If
End Sub

最佳答案

或者您可能会完全错过剪贴板:

If Not CopyRange Is Nothing Then
Dst.Range("A1").Resize(CopyRange.Rows.Count, CopyRange.Columns.Count).Value = CopyRange.Value
End If

关于vba - Excel VBA - 粘贴为值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29311540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com