我在尝试粘贴列的值1
,2
,& 4
和仅列3
的公式。excel多个粘贴特价
我可以任一或所有的4列工作,但我不知道如何与.PasteSpecial xlPasteFormulasAndNumberFormats
Sub FindData() 'Find Both
Application.ScreenUpdating = False
Dim datasheet As Worksheet 'data copied from
Dim reportsheet As Worksheet 'data pasted to
Dim partone As String 'search criteria 1
Dim parttwo As String 'search criteria 2
Dim finalrow As Integer 'find last used row
Dim i As Integer 'row counter
'set variables
Set datasheet = Sheet2
Set reportsheet = Sheet4
partone = reportsheet.Range("E6").Value
parttwo = reportsheet.Range("F6").Value
'clear old data from reort sheet
reportsheet.Range("A10:D110").ClearContents
'goto datasheet and start searching and copying
datasheet.Select
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
'loop through the rows to find matching records
For i = 10 To finalrow
If Cells(i, 5) = partone And Cells(i, 6) = parttwo Then
Range(Cells(i, 1), Cells(i, 4)).Copy
reportsheet.Select
Range("A101").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
datasheet.Select
End If
Next i
reportsheet.Select
Range("E9:F9").Select
Application.ScreenUpdating = True
End Sub
添加如果条款对你目前如果要检查是否I = 3? – SJR
不是你的问题的答案,但你不需要继续使用'someSheet.Select',直接使用工作表变量更安全,更快捷。例如。 'finalrow = datasheet.Cells(Rows.Count,1).End(xlUp).Row'。如果您不想继续引用同一个工作表,请使用'With'语句块。 – SteveES
@SteveES如果你给出建议,给它正确的,你的'finalrow'不是完全合格的,它需要是'finalrow = datasheet.Cells(datasheet.Rows.Count,1).End(xlUp).Row' –