如何将复制的可见行从顶部插入到现有数据中

时间:2017-03-22 10:52:53

标签: vba excel-vba word-vba excel

如何将复制的行插入到相同的现有数据中,我想在现有数据和同一张表中插入我在下面给出的代码中复制的行

Name    Location    Salary
Sy      Hyd         12,000
Ay      Hyd         13,000
Raju    Hyd         15,000

我想从上表复制名称位置和工资,并将复制的数据从顶部插入到上面的表中(标题下方)

Sub Referral()

Application.ScreenUpdating = False

With Sheets("Sheet3")

    'this is generic, you may need to adjust this based on your sheet and data needs
    Intersect(.UsedRange, .UsedRange.Offset(1)).SpecialCells(xlCellTypeVisible).Copy

End With

'goes to cell below last used cell in column A
Sheets("Sheet4").Cells(Rows.Count, 1).End(xlUp).Offset(1).PasteSpecial xlPasteValues


Application.ScreenUpdating = True 'don't forget to turn on your ScreenUpdating again!

End Sub

1 个答案:

答案 0 :(得分:0)

我刚接过你的代码并改变了一些东西

Sub Referral()

Application.ScreenUpdating = False

With Activesheet
    .range(.cells(2,1),.cells(.cells(.rows.count,1).end(xlup).row,.cells(1,.columns.count).end(xltoleft).column)).Copy
    .Cells(2, 1).PasteSpecial xlPasteValues
End With

Application.ScreenUpdating = True 

End Sub