我正在尝试打开特定文件夹中的所有Excel文件,并尝试从每个Excel文件中复制标题(基于C列中的标题 )并基于该值我需要复制F列中的值
我正在尝试下面的代码,但它给我扔了一个
运行时错误450:“参数数量错误或属性分配无效”
FolderName = Worksheets("Copy").Cells(2, "K").Value & "\"
If FolderName <> "\" Then
FileName = Dir(FolderName & "*.xl*")
If FileName <> "" Then
Application.ScreenUpdating = False
While FileName <> ""
Set wbTarget = Workbooks.Open(FileName:=FolderName & FileName, UpdateLinks:=False, ReadOnly:=True)
i = 1
For Each cell In wbTarget.Sheets(1).Range("ID", "Name", "Class", "Div", "Sub1", "Sub2", "Sub3", "Sub4", "Sub5")
arr(i) = Cells(i, 6).Value
i = i + 1
Next cell
With Worksheets("Copy")
.Cells(.Cells(.Rows.Count, "A").End(xlUp).Row + 1, 1).Resize(, UBound(arr)).Value = arr
End With
wbTarget.Close False
Set wbTarget = Nothing
Erase arr
FileName = Dir
Wend
Application.ScreenUpdating = True
除了输出与ID,Name,..... Sub5匹配时,它应该复制F列中的值并粘贴到另一张纸上。
建议我我要去哪里错了,应该做出什么更改。