问题描述
您好我想问。
我的情况是
表1包括从A列到Z的值。
表5包括来自A栏到Z栏。
两张纸,Z栏都有共同的价值。
我想使用运行到
的VBA代码1.将(表5)的Z列与Sheet的Z列匹配1.
2.如果找到匹配,则复制,粘贴表5(*匹配)的行到表1的相应行。
请帮忙!
我的尝试:
使用.Range(Z1:Z和LastRow)
。自动填充字段:= 1,Criteria1:== *& strSearch& *
。偏移(1,0).SpecialCells(xlCellTypeVisible).Cells.Copy
Sheets(Sheet5)。激活
DestinationRange.PasteSpecial
结束
Hi i would like to ask.
My situation is
Sheet 1 includes value from Column A to Z.
Sheet 5 includes value from Column A to Z.
Both sheet, Column Z has common value.
I would like to use a VBA code that run to
1. match Column Z of (Sheet 5) to Column Z of Sheet 1.
2. If match found, then copy, paste the row from Sheet 5(*that match), to Sheet 1 respective row.
Please help!
What I have tried:
With .Range("Z1:Z" & LastRow)
.Autofilter Field:=1, Criteria1:="=*" & strSearch & "*"
.Offset(1,0).SpecialCells(xlCellTypeVisible).Cells.Copy
Sheets("Sheet5").activate
DestinationRange.PasteSpecial
End With
推荐答案
Sub CP_CopyPasteRow()
Dim lastrow As Long
'Disable Alert (Warning) Messages in Excel
Application.DisplayAlerts = False
With Sheets("Sheet5")
'get the last row index with data
lastrow = .Cells(.Rows.Count, "Z").End(xlUp).Row
For r = 1 To lastrow
'loop each to matzh Z column, if match copy A:Y to Sheet 1
If Worksheets("Sheet1").Cells(r, Range("Z" & 1).Column).Value = .Cells(r, Range("Z" & 1).Column).Value Then
.Rows(r).Copy
Worksheets("Sheet1").Range("A" & r & ":Y" & r).PasteSpecial xlPasteValues
End If
Next r
End With
'enable alert
Application.DisplayAlerts = True
End Sub
这篇关于Vba在2张纸上搜索列匹配,并从第2页到第1页粘贴行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!