I want to find a particular cell in an opened worksheet and copy the data 3 cells to the right into the main workbook (not the one that has just been opened).
The macro below loops through all the files in a txt doc and opens and closes them. In each file is a cell called ADA and I want to copy the cells 3 to the right, however ADA is not always in the same place so I need to search for it. e.g find the cell ADA and say it is in E6 in that workbook, I need to copy E6 along with H6,I6 and J6 into the original main workbook that I am running the macro from.
Sub GatherData()
Dim objFSO As Object
Dim objWB As Workbook
Dim strFN As String
Dim objTF As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTF = objFSO.OpenTextFile("U:\Time series project\doclist.txt")
On Error Resume Next
Do While Not objTF.AtEndOfStream
strFN = objTF.readline()
Set wb = Workbooks.Open(strFN)
If wb Is Nothing Then
Debug.Print strFN
Else
wb.Close False
Set wb = Nothing
End If
Loop
On Error GoTo 0
End Sub
I was thinking of adding something like
Dim c As Range
Dim newcell
Dim tmp
Dim wrkbk As WorkBook
Dim sht As WorkSheet
Set c = .Find(findValues(i), LookIn:=xlFormulas)
If Not c Is Nothing Then
newcell = c.Offset(0, 4).Value
Do
tmp.Offset(0, 2).Value = tmp.Value
tmp.Offset(0, 3).Value = newcell
End If
but can't get this concept to fit into the first code.