我在此處有代碼循環遍歷文件列表;打開它們,提取數據並將其移入主工作簿。我想要做的事情得到它,所以abel的數據是在列C和D,然後把VARO在F和G等等我看到的問題是,放置代碼是在循環內,所以對於每個我它只會寫在上一行,而不是在不同的列在一起!如何更改每個循環的輸出位置並運行多個循環
Sub Source_Data()
Dim r
Dim findValues() As String
Dim Wrbk As Workbook
Dim This As Workbook
Dim sht As Worksheet
Dim i
Dim tmp
Dim counter
Dim c As Range
Dim firstAddress
Dim rng As Range
ReDim findValues(1 To 3)
findValues(1) = "abel"
findValues(2) = "varo"
findValues(3) = "Tiger"
counter = 0
r = Range("A1").End(xlDown).Row
Set rng = Range(Cells(1, 1), Cells(r, 1))
Set This = ThisWorkbook
For Each tmp In rng
Workbooks.Open tmp
Set Wrbk = ActiveWorkbook
Set sht = ActiveSheet
For i = 1 To 3
With sht.Range(Cells(1, 1), Range("A1").SpecialCells(xlCellTypeLastCell))
Set c = .Find(findValues(i), LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Offset(0, 2).Value
Do
This.Activate
tmp.Offset(0, 2).Value = tmp.Value
tmp.Offset(0, 3).Value = firstAddress
Set c = .FindNext(c)
counter = counter + 1
Loop While Not c Is Nothing And c.Value = firstAddress
End If
End With
Wrbk.Activate
Next
Wrbk.Close
Next tmp
End Sub
**編輯:**我知道它可以通過增加一個乘數「我」的偏移值來完成,但是這使事情變得大於他們需要的是,如果我想搜索50個關鍵字
您需要添加一些東西到例如'tmp.Offset(0,2 +計數器).Value =' – Davesexcel
只是編輯帖子,說你寫這個戴夫:)只是希望這可能是一種簡單的方法。在我的實際文檔中,我可能會採用50個關鍵字的7個值,所以它最小可以達到400個單元格:/編輯:等等,數學是錯誤的。它會比這更廣泛!!!!!! – IIJHFII