我真的需要帮助,将以下数据集粘贴为值。
我目前想在我的工作簿中循环浏览某些工作表,并从选定的工作表中复制和粘贴数据。
但是,我不确定如何将要处理的数据粘贴为值。
我编写了以下代码来循环浏览所需的工作表,并从每个工作表中选择所需的日期。但是,当我将此数据粘贴到“主数据”选项卡中时,似乎无法粘贴为值。
Sub exa()
Dim wks As Worksheet
For Each wks In ThisWorkbook.Worksheets
If Not wks.Name = "Master Data" _
And Not wks.Name = "Query --->" _
And Not wks.Name = "Pivot Portfolio Movement" _
And Not wks.Name = "PortfolioMovement - All" _
And Not wks.Name = "Bank Holidays" _
And Not wks.Name = "Property" _
And Not wks.Name = "Postcodes" _
And Not wks.Name = "Product" _
And Not wks.Name = "PartRedemption" _
And Not wks.Name = "Wrap" _
And Not wks.Name = "Completions Database" _
And Not wks.Name = "Default" _
And Not wks.Name = "ReturningBorrower" _
And Not wks.Name = "Extensions" _
And Not wks.Name = "PortfolioMovement" _
And Not wks.Name = "Drawdowns" _
And Not wks.Name = "Dev Interest WIP" _
And Not wks.Name = "Write Off Loans" _
And Not wks.Name = "Interest Rate" _
And Not wks.Name = "Admin" _
And Not wks.Name = "Datatape --->" _
And Not wks.Name = "Data" _
And Not wks.Name = "Drawn Balance by Loan" _
And Not wks.Name = "Sheet1" Then
wks.Range("H2:N2" & wks.Cells(Rows.Count, "N").End(xlUp).Row).Copy _
Destination:=Worksheets("Master Data").Cells(Rows.Count, "A").End(xlUp).Offset(1)
End If
Next
End Sub
答案 0 :(得分:0)
要粘贴为值,您需要使用Range.PasteSpecial method:.PasteSpecial xlPasteValues
请注意,如果您使用工作表数组来跳过,则可以减少代码,如下所示:
Option Explicit
Public Sub exa()
Dim SkipWorksheets As Variant
SkipWorksheets = Array("Master Data", "Query --->", "Pivot Portfolio Movement", "PortfolioMovement - All", _
"Bank Holidays", "Property", "Postcodes", "Product", "PartRedemption", "Wrap", _
"Completions Database", "Default", "ReturningBorrower", "Extensions", _
"PortfolioMovement", "Drawdowns", "Dev Interest WIP", "Write Off Loans", _
"Interest Rate", "Admin", "Datatape --->", "Data", "Drawn Balance by Loan", "Sheet1")
Dim Wks As Worksheet
For Each Wks In ThisWorkbook.Worksheets
If Not (UBound(Filter(SkipWorksheets, Wks.Name)) > -1) Then
Wks.Range("H2:N2" & Wks.Cells(Rows.Count, "N").End(xlUp).Row).Copy
Worksheets("Master Data").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
End If
Next Wks
End Sub