【发布时间】:2019-04-05 15:10:56
【问题描述】:
我有 400 个 excel 文件(技术报告),每个文件都有 5 个不同名称的选项卡。我需要创建一个主电子表格,其中包含每个报告的某些信息(信息始终在同一个选项卡上)
我有一个代码(从此处复制),可用于在特定单元格中查找信息。
问题是报告的结构不一致,好消息是在我搜索的信息的相邻单元格上,总是有相同的文本“水位:”。
我正在寻找一个可以搜索此文本字符串、复制相邻单元格并将其返回到此主电子表格的宏。
请看我提到的代码:
Sub Test()
' Adjust the path below as required
MyPath = "C:\Users\bcf00637\Desktop\pilelogs\V2\" ' Set the path.
myname = Dir(MyPath, vbNormal) ' Retrieve the first entry.
Do While myname <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If myname <> "." And myname <> ".." Then
If (GetAttr(MyPath & myname) And vbNormal) = vbNormal Then
ActiveCell.FormulaR1C1 = "='" & MyPath & "[" & myname & "]Approval Form'!R1C1" ' change the part after the ] to your sheets name
' also change the R1C1 on the end to pick up the cell you want ie R2C3 for cell C2
' do NOT change the 1st one (.FormulaR1C1) this is part of the command.
ActiveCell.Offset(0, 1).Value = myname
ActiveCell.Offset(1, 0).Select
End If
End If
myname = Dir
Loop
End Sub
【问题讨论】: