excel - 如何从打开的文件中获取数据?
问题描述
我有这段代码,
工作表:“主要”B3:我在文件中搜索的内容。
工作表“AX”:在哪里搜索。
我想在另一个以字母开头的打开的工作簿中搜索:ECL_
Sub FindandKopy()
Dim CellContents As String
Dim rng As Range
Dim loDeinWert As String
Dim sfirstaddress As String
loDeinWert = Worksheets("main").Range("B3").Value
Set rng = Worksheets("AX").Range("B:B").Find(loDeinWert)
If rng Is Nothing Then
MsgBox "Data " & loDeinWert & " not found!"
Else
sfirstaddress = rng.Address
Do
rng.EntireRow.Copy
Worksheets("Main").Cells(Rows.Count, "A").End(xlUp) _
.Offset(6, 0).PasteSpecial Paste:=xlPasteAll
Set rng = Worksheets("AX").Range("B:B").FindNext(rng)
Loop While Not rng Is Nothing And rng.Address <> sfirstaddress
End If
End Sub
解决方案
如果您需要查找已经打开的工作簿,您可以遍历所有工作簿并检查每个工作簿名称:
Dim ECLWb As Workbook
Dim wb As Workbook
For Each wb in Application.Workbooks
If wb.Name Like "ECL_*" Then
Set ECLWb = wb
Exit For
End If
Next wb
If ECLWb Is Nothing Then
MsgBox "ECL_* not found."
Exit Sub
Else
'use that workbook like
ECLWb.Worksheets("AX")…
End If
推荐阅读
- r - 从生存包生成风险表
- css - 如何创建 3D 动画立方体
- python-3.x - 匹配版本号和月份索引的正则表达式
- javascript - 如何在两个字符串之间重复一个字母的次数
- python - 灵活的形状不适用于使用 coremltools 4 的 ONNX 到 MLModel 转换
- c - 如何将 void* 成员从 struct 转换为 int 或 char*
- javascript - 如何检查 Div 是否在屏幕上 Javascript
- exception - OppRecordCombo:BeforeUpdate 的执行导致:System.FinalException:SObject 行不允许错误()
- javascript - 如何将报价保存到特定的工作日?
- javascript - 当条件为假时,异步函数内的循环会额外执行一次