我正在尝试将一些数据合并到我创建的特定Excel模板中。我的数据标题为PAxxx.xx,其中x可以是0-9之间的任何数字。有没有办法可以搜索我当前的工作簿中的特定标题" PAxxx.xx"并将其填充到我创建的模板字段中。
我目前在VBA中有这个搜索功能:
Sub CopyPasteCellData()
Dim FirstAddress As String
Dim searchTerms As Variant
Dim Rcount As Long
Dim I As Long
Dim Rng As Range
Dim currentWorkbook As Workbook
Dim newWorkbook As Workbook
Dim currentWorksheet As Worksheet
Dim newWorksheet As Worksheet
Set currentWorkbook = Workbooks("LVX Release 2015 (2).xlsm")
Set currentWorksheet = currentWorkbook.Sheets("PA5179.01")
Set newWorkbook = Workbooks("Test.xlsx")
Set newWorksheet = newWorkbook.Sheets("Sheet1")
'newWorksheet.Range("C2").Value = currentWorksheet.Range("A1").Value
searchTerms = Array("PA")
With currentWorksheet.UsedRange
Rcount = 0
For I = LBound(searchTerms) To UBound(searchTerms)
Set Rng = .Find(What:=searchTerms(I), _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
FirstAddress = Rng.Address
Do
Rcount = Rcount + 1
newWorksheet.Range("A" & Rcount).Value = Rng.Value
Set Rng = .FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress
End If
Next I
End With
End Sub
只是不确定如何在工作表中搜索所有数据集PAxxx.xx。
提前致谢:)
答案 0 :(得分:0)
这是一个基本原则,如何遍历所有工作表并找到PAxxx.xx - &gt;如果您需要更改验证,请阅读Like运算符的说明 - &gt;
Node newNode = Node(2);