我已經有一個問題,我需要基於一組特定的值(幾個名稱)從2個工作簿中的數據複製到一個高手在第3列中。我是VBA的新手,可能我無法精確地問這個問題找到答案,對此表示歉意。請你幫我,我需要提取數據的行從每個工作簿只有如果列3包含我正在尋找一個名字。我有下面的代碼從特定文件夾中的每個工作簿中提取數據,但它抓住了一切。如何根據從多個工作簿特定的單元格的值數據複製到主簿
Sub copyDataFromManyFiles()
With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
End With
Dim FolderPath As String, FilePath As String, FileName As String
FolderPath = "C:\Users\Jasiek\Desktop\Yuuuge MacroTest\"
FilePath = FolderPath & "*ennik*.xl*"
FileName = Dir(FilePath)
Dim lastrow As Long, lastcolumn As Long
Do While FileName <> ""
Workbooks.Open (FolderPath & FileName)
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(2, 1), Cells(lastrow, lastcolumn)).Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets(1).Range(Cells(erow, 1), Cells(erow, 30))
FileName = Dir
Loop
With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With
'Call removeDuplicates
End Sub
我應該如何修改代碼以在複製行之前過濾數據?因爲有100k +記錄,所以我關心性能。我真的很感激幫助。謝謝。最簡單的方法進行可能會使用INSTR()方法來確定電池值是否具有你是一個名字:您正在處理一個固定的名稱(即2-3)的