将一行和pastespecial值行复制到另一个工作表(或只是行的一部分)

时间:2014-09-04 20:51:26

标签: excel vba paste

PasteValues是VBA中最令人沮丧的事情!可以大大使用一些帮助。 简而言之,我正在尝试将一行和pastespecial值复制到一个单独的工作表上的另一行。我认为这是一个问题,所以我然后修改我的范围并尝试粘贴,也无济于事。我甚至尝试录制宏,生成的代码几乎与我的完全相同。

有人可以帮忙吗?我一直在看这个太久了:/

Sub CopyXs()

Dim counter As Double
Dim CopyRange As String
Dim NewRange As String

counter = 2

For Each Cell In ThisWorkbook.Sheets("LD_Tracker_CEPFA").Range("A7:A500")
If Cell.Value = "X" Then
Sheets("Upload_Sheet").Select
matchrow = Cell.Row
counter = counter + 1



Let CopyRange = "A" & matchrow & ":" & "Y" & matchrow
Let NewRange = "A" & counter & ":" & "Y" & counter

Range(CopyRange).Select
Selection.Copy

Sheets("Final_Upload").Select
ActiveSheet.Range(NewRange).Select

Selection.PasteSpecial Paste = xlPasteValues

Sheets("Upload_Sheet").Select
End If

Next


End Sub

1 个答案:

答案 0 :(得分:0)

我还在使用Paste.Special。这段代码适合我。为Paste.Special录制宏时获得的代码不起作用。首先必须定义一个范围,然后使用Paste.Special

的代码

范围(某事).PasteSpecial Paste:= xlPasteValues Application.CutCopyMode = False

'This code works for me:    
'**Select everything on the active sheet**

Range("A1").Select
Dim rangeTemp As Range
Set rngTemp = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
If Not rngTemp Is Nothing Then Range(Cells(4, 1), rngTemp).Select
End if

 ' **Copy the selected range**
Selection.Copy

'**Select the destination and go to the last cel in column A and then go 2 cells down
'and paste the values**

Sheets("your sheet name").Select
Range("A" & Cells.Rows.Count).End(xlUp).Offset(2, 0).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False

    **'Select the last cell in column A**

Range("A" & Cells.Rows.Count).End(xlUp).Select