Sub main()
Set dic = CreateObject("scripting.dictionary")
arr = Range("A1").CurrentRegion
For i = 1 To UBound(arr)
If dic.exists(arr(i, 2)) = False Then
dic(arr(i, 2)) = arr(i, 1)
Else
If dic(arr(i, 2)) <arr(i, 1) Then
dic.Remove arr(i, 2)
dic(arr(i, 2)) = arr(i, 1)
End If
End If
Next i
[E1].Resize(dic.Count, 1) = Application.Transpose(dic.keys)
[D1].Resize(dic.Count, 1) = Application.Transpose(dic.items)
End Sub
PrivateConstDirPath$="C:\"'指向查找的路径Subaa()
DimFilename$
Dimi&
DimWbAsWorkbook,RngAsRange
Application.ScreenUpdating=False
Application.DisplayAlerts=False
OnErrorResumeNext
WithWorksheets("总表")
Fori=1To.[B65536].End(3).Row
IfLen(.Cells(i,2))0Then
Filename=DirPath&""&.Cells(i,"B")&".xls"
IfLen(Dir(Filename))0Then
SetWb=GetObject(Filename)
WithWb.Worksheets("材料")
IfErr.Number0ThenGoTol
SetRng=.[B:B].Find(what:="水泥砖")
IfNotRngIsNothingThen
Worksheets("总表").Cells(i,"C")=Rng.Offset(0,1).Value
EndIf
EndWith
l:
Wb.CloseFalse
EndIf
EndIf
Next
EndWith
Application.ScreenUpdating=True
Application.DisplayAlerts=True
EndSub
方法/步骤如下:
1、双击打开桌面的EXCEL;
2、单击右上角的OFFICE图标,找到EXCEL选项,单击打开;
3、勾选在功能区显示“开发工具”选项卡,单击确定按钮完成修改。
4、单击菜单栏的开发工具,然后找到Visual Basic单击打开便可以进行相关的VBA编程。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)