在工作表和隐藏行之间匹配范围,并将数据粘贴到另一个工作表的最后一行

时间:2019-01-31 16:23:27

标签: excel vba range match

我希望我可以在以下方面获得帮助。预先感谢您提出的所有建议。

说明:我有3个工作表。我正在尝试将A列工作表1(IRA)中的值复制到工作表2(XVD) 如果工作表1中的值数量与工作表3(POV)中的值总数< / p>

第3张(POV)应用了所需的过滤器。目标是将IRA中的值与POV过滤后的行匹配,如果匹配,则只需将IRA的A列中的总值附加到XVD的A列中的最后一行。

问题:由于IF语句无法正确执行,因此复制粘贴无法正常工作且无法运行。

此外,当过滤的行超过1800行时,XVD的lastrow(仅检查可见单元格)返回的值仅为3。

Sub copycontactsiratopov()

'activate source sheet
ActiveWorkbook.Worksheets("IRA").Activate

'define last rows for all three sheets
LastrowIRA = ActiveSheet.Range("A1").CurrentRegion.Rows.count

'there are over 1800 values but it keeps showing only 3?!
LastRowXVD = ActiveWorkbook.Sheets("RevereseVlookup").Range("A1").SpecialCells(xlCellTypeVisible).Rows.count
LastRowPOV = ActiveWorkbook.Sheets("POV").Range("A1").CurrentRegion.Rows.count

'copy the data needed, values are generally less than 10000 rows
ActiveWorkbook.ActiveSheet.Range("A2:A10000").Copy

'if the number of lastrow in source sheet is equal to total VISIBLE last row within reference sheet then
If LastrowIRA = LastRowXVD Then

'copy the range from source to destination
Worksheets("POV").Range("A" & LastRowPOV + 1).Value = Worksheets("IRA").Range("A2:A10000").Value


'else display msg for error handling
Else: MsgBox "Row Count between IRA and XVD tab is off! *CHECK*"

End If

End Sub

1 个答案:

答案 0 :(得分:0)

您的粘贴命令在哪里,看不到。

ActiveWorkbook.ActiveSheet.Range("A2:A10000").Copy
Workbooks("put your wb name here").sheets("POV").Range("A2").paste

类似的东西应该起作用