|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Public sfso, sfd, sfl, Arr, Brr
Sub Find()
Dim sfso, sfd, sfl, Arr, Brr
Rem 定义文件夹选取对话框
Rem 打开工作簿,在"BOM"工作表中将某列为作选择对像,并将该列单元格值写入数组Arr
Rem 将Arr中值为"贴片功率电感"或"贴片磁心电感"所在行号记录,并返选该行的B列至D列单元格内容,并复制到新表格中
'Set sfso = CreateObject("scripting.FsoSystemObject")
'Declare a variable as a FileDialog object.
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Declare a variable to contain the path
'of each selected item. Even though the path is aString,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant
'Use a With...End With block to reference the FileDialog object.
With fd
'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the button.
.A
llowMultiSelect = True
If .Show = -1 Then
'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems
a (vrtSelectedItem)
Next vrtSelectedItem
'The user pressed Cancel.
Else
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing
End Sub
Function a(pth$)
Dim Wb
Dim sh As Worksheet
Set sh = ThisWorkbook.Worksheets
Set sfso = CreateObject("Scripting.FileSystemObject")
sfd = sfso.GetFile(pth)
For Each Wb In sfd.Files
'Wb.Open
Arr() = Wb.Range("C6:D" & Range(D6).End(xlDown).Row)
n = 6
For i = 6 To UBound(Arr)
If Arr(i, d).Value = "贴片磁芯电感" Or Arr(i, d) = "贴片功率电感" Then
n = n + 1
For s = 3 To 5
Brr(n, s) = Arr(i, s)
Next s
End If
Next i
sh.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(n, UBound(Brr, 2)) = Brr
Wb.Close
Next Wb
End Function
这段代码逻辑错在哪?????
|
|