第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用特定的單詞復制Excel中的一行并粘貼到另一個Excel工作表上?

如何使用特定的單詞復制Excel中的一行并粘貼到另一個Excel工作表上?

ibeautiful 2019-06-13 14:55:07
如何使用特定的單詞復制Excel中的一行并粘貼到另一個Excel工作表上?我檢查了一堆不同的帖子,似乎找不到我要找的確切代碼。而且我從來沒有用過VBA在此之前,我試圖從其他帖子中獲取代碼,并輸入我的信息以使其發(fā)揮作用。還沒有運氣。在工作中,我們有一個工資系統(tǒng)EXCEL..我在尋找我的名字"Clarke, Matthew"然后復制該行并將其粘貼到我在桌面上保存的工作簿上。"Total hours".
查看完整描述

3 回答

?
拉丁的傳說

TA貢獻1789條經(jīng)驗 獲得超8個贊

試測試

Sub Sample()
    Dim wb1 As Workbook, wb2 As Workbook    Dim ws1 As Worksheet, ws2 As Worksheet    Dim copyFrom As Range    
    Dim lRow As Long '<~~ Not Integer. Might give you error in higher versions of excel
    Dim strSearch As String

    Set wb1 = ThisWorkbook    Set ws1 = wb1.Worksheets("yourSheetName")

    strSearch = "Clarke, Matthew"

    With ws1        '~~> Remove any filters
        .AutoFilterMode = False

        '~~> I am assuming that the names are in Col A
        '~~> if not then change A below to whatever column letter
        lRow = .Range("A" & .Rows.Count).End(xlUp).Row        With .Range("A1:A" & lRow)
            .AutoFilter Field:=1, Criteria1:="=*" & strSearch & "*"
            Set copyFrom = .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow        End With

        '~~> Remove any filters
        .AutoFilterMode = False
    End With

    '~~> Destination File
    Set wb2 = Application.Workbooks.Open("C:\Sample.xlsx")
    Set ws2 = wb2.Worksheets("Sheet1")

    With ws2        If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
            lRow = .Cells.Find(What:="*", _
                          After:=.Range("A1"), _
                          Lookat:=xlPart, _
                          LookIn:=xlFormulas, _
                          SearchOrder:=xlByRows, _
                          SearchDirection:=xlPrevious, _
                          MatchCase:=False).Row        Else
            lRow = 1
        End If

        copyFrom.Copy .Rows(lRow)
    End With

    wb2.Save
    wb2.CloseEnd Sub


查看完整回答
反對 回復 2019-06-13
?
臨摹微笑

TA貢獻1982條經(jīng)驗 獲得超2個贊

擴展timrau在他的評論中所說的內(nèi)容,您可以使用autofilter函數(shù)查找包含您名字的行。(請注意,我假設您打開了源代碼工作簿)

Dim curBook As WorkbookDim targetBook As WorkbookDim curSheet As WorksheetDim targetSheet As WorksheetDim lastRow As IntegerSet 
curBook = ActiveWorkbookSet curSheet = curBook.Worksheets("yourSheetName")'change the Field number to the correct columncurSheet.
Cells.AutoFilter Field:=1, Criteria1:="Clarke, Matthew" 'The Offset is to remove the header row from the copycurSheet.AutoFilter.
Range.Offset(1).Copy  
curSheet.ShowAllData 

Set targetBook = Application.Workbooks.Open "PathTo Total Hours"Set targetSheet = targetBook.WorkSheet("DestinationSheet")lastRow
 = Cells.Find(What:="*", After:=Range("A1"), LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row

targetSheet.Cells(lastRow + 1, 1).PasteSpecial

targetBook.Save
targetBook.Close

如您所見,我將占位符放在工作簿的特定設置中。


查看完整回答
反對 回復 2019-06-13
?
米脂

TA貢獻1836條經(jīng)驗 獲得超3個贊

我知道這是老生常談,但對于其他人來說,尋找如何做到這一點,可以用一種更直接的方式:

Public Sub ExportRow()
    Dim v    Const KEY = "Clarke, Matthew"
    Const WS = "Sheet1"
    Const OUTPUT = "c:\totalhours.xlsx"
    Const OUTPUT_WS = "Sheet1"

    v = ThisWorkbook.Sheets(WS).Evaluate("index(a:xfd,match(""" & KEY & """,a:a,),)")
    With Workbooks.Open(OUTPUT).Sheets(OUTPUT_WS)
        .[1:1].Offset(.[counta(a:a)]) = v        .Parent.Save: .Parent.Close    End WithEnd Sub


查看完整回答
反對 回復 2019-06-13
  • 3 回答
  • 0 關注
  • 805 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號