Sub 市值汇总表() Dim findDate As String Dim a As Integer findDate = "2018/8/15" a = 1 Application.ScreenUpdating = False myfile = Dir(ThisWorkbook.Path & "\*.xls*") ThisWorkbook.Worksheets(1).Cells(1, 1) = "文件名称" ThisWorkbook.Worksheets(1).Cells(1, 2) = "简称" ThisWorkbook.Worksheets(1).Cells(1, 3) = findDate & "市值" Do While myfile <> "" If myfile <> ThisWorkbook.Name Then Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & myfile) a = a + 1 Set aftersheet = wb.ActiveSheet.Range("C:C") aftersheet.NumberFormat = "yyyy/m/d" Set findRange = aftersheet.Find(DateValue(findDate)) ThisWorkbook.Worksheets(1).Cells(a, 1) = myfile ‘文件名称即代码 ThisWorkbook.Worksheets(1).Cells(a, 2) = wb.ActiveSheet.Range("b2") ‘公司简称 If Not findRange Is Nothing Then ThisWorkbook.Worksheets(1).Cells(a, 3) = wb.ActiveSheet.Range("N" & findRange.Row) ‘当日市值 Else ThisWorkbook.Worksheets(1).Cells(a, 3) = "无当日市值" ‘当日市值 End If wb.Close False End If myfile = Dir Loop Application.ScreenUpdating = True MsgBox "完成" End Sub
原文:https://www.cnblogs.com/mgblog/p/13219266.html