Sub SelectiveCopyPaste()
Dim WB As Workbook, Data1 As Range, Data2 As Range, RowData As Long, i As Long, FilePath As String
FilePath = "C:\Program Files\Microsoft Office\Office\RS.xlsb" 'Add your own file path
Set WB = Workbooks.Add(FilePath)
Set Data1 = Range("A2:A14") 'Change this accordingly
'Change this accordingly
Set Data2 = WB.Worksheets("RS_Summary").Range("Set the range you want to copy here")
RowData = Data1.Rows.Count
For i = 1 To RowData
If Data(i, 1) = Cells(1, 1) Then
Data2(i, 1).Copy Data1(i, 2) 'Change this too
Exit For
End If
Next
End Sub
1
最后,我找到了解决这个问题的方法 . 这是我用来帮助我的代码:
Sub PasteValues()
Dim RowData As Long, i As Long
Set Data = Range("A2:A108")
RowData = Data.Rows.Count
For i = 1 To RowData
If Data(i, 1) = Cells(1, 1) Then
Range(Cells(i + 1, 2), Cells(i + 1, 16)).Copy
Range(Cells(i + 1, 2), Cells(i + 1, 16)).PasteSpecial xlPasteValues,
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Next i
Application.CutCopyMode = False
End Sub
2 回答
你看起来像这样吗?
最后,我找到了解决这个问题的方法 . 这是我用来帮助我的代码: