我試圖從大量的工作表中複製行。 根據不同的版本,我有多個與某個文檔相關的行。 因此,一些行具有相同的參考,相同的名稱,但具有不同的版本/創建日期。我想複製到另一個工作表(例如Sheet2)每個文檔的最新版本。基於多個單元格值複製行
我已經嘗試了至少幾個while循環來檢查所有行和如果檢查日期的值,但我沒有使它的工作,我不知道它是否是一種有效的方式做到這一點。 這裏是我的問題的圖片和代碼的一部分,我寫道:
Dim Name as String
Dim Dates as Date
With Sheets(Sheet1)
Application.DisplayAlerts = False
Name = Cells(1,3) 'Initialise Name
Dates = Cells(1,5) 'Initialise Dates
LineCopy = 1 'The line we'll copy
Line = 1 'The line we use to check the sheet
While Name <> "" 'if the name is not empty, ie there are no documents left
While Sheets(Sheet1).StrComp(Name, .Cells(Line, 3)) = True 'WHile you are working with a same name document
If .Cells(Line, 5) > Dates Then 'If the document is older, then choose it.
Dates = .Cells(Line, 5)
Else
LineCopy = Line 'If there are no older documents, then it's the one to copy
Sheets(Sheet1).Range("A" & LineCopy & ":" & "E" & LineCopy).Copy ' Copy the oldest document
Sheets(Sheet2).Paste
End If
Line = Line + 1 ' Increment the Line in the second while to check every line
Wend
Name = .Cells(LineCopy + 1, 6) 'After the first while, let's change name to the second document and do it all over again.
Wend
所以你想複製基於最新日期的行與獨特的參考。我對嗎? –
根據我的理解,你需要這個函數'= MAX(E2:E4)'它給你最近的日期 –
是的,但是我不知道每個文檔有多少行。 –