ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 763|回复: 0

求大神审核代码!!!!逻辑错了么????

[复制链接]

TA的精华主题

TA的得分主题

发表于 2017-10-28 22:54 来自手机 | 显示全部楼层 |阅读模式
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
这段代码逻辑错在哪?????
rBBmQ1n0mMaASTtuAAFC2RBGsg0118.PNG
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-20 13:30 , Processed in 0.033329 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表