简体   繁体   中英

Copying a row in excel from one sheet to another after searching for a given value

Disclaimer... I am not looking for someone to code this for me, just point me in the correct direction or give me some examples I can work with.

Problem: I have a workbook that has two pages. the first if formatted like this

Hostname       Chassis Service Tag Asset Tab   Location    u   
LCLDHV003-25    PE R610 1*V4YQ1     1*1315  D3SF85.08      21
LCMNTYPXYB02    PE R610 BZ00L1      19368   x3SD04.34      36
LEMAILMIG001    PE 1950 9ZVSJ1      12078   x3SE07.12      29
LPASSCDB01-01   PE R710 3XSVH1      11415   P3SD02.22      03

I need to search in in the location field for a given value (example x3SD04) and then insert this row into the second table. I need to have the existing data moved down the page.

I have seen vlookup index, match and some vba options. just that everything I have tried has failed.

try this:

Sub test()
    Dim SearchString$, cl As Range, n&
    SearchString = "x3SD04"
    n = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row + 1 'get row for insert copied row
    Set cl = Sheets("Sheet1").Cells.Find(SearchString) 'find range with SearchString
    If Not cl Is Nothing Then 'if SearchString exist in sheet then copy 
        Sheets("Sheet1").Rows(cl.Row).Copy Sheets("Sheet2").Rows(n)
    End If
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM