I have several data files that i need to process. My code uses a macro to go through each of the data files - run another macro to do some calculations - out put that result on the top row of the data file. Now I want specific column data from the top row from each file to be sent to another file - called summary so that i can have a dashboard looking sheet with relevant information about all the files in the folder.
My code is below. I am having difficulties with adding the data to the new file inside the for loop while the data is being manipulated the first time.
Sub LoopThroughFiles(dirName)
Dim currWorkBook As String
'Dim i As Integer ' for going to next row in mastersheet
currWorkBook = ActiveWorkbook.Name
FolderName = dirName ' enter the folder where all the files are located
If Right(FolderName, 1) <> Application.PathSeparator Then FolderName = FolderName & Application.PathSeparator
'make sure you change the file extension here appropriately - *.xls or *.xlsm
Fname = Dir(FolderName & "*.xl*")
'loop through the files
Do While Len(Fname)
'For i = 4 To 6 ' to advance rows in the master sheet where the data is collected
With Workbooks.Open(FolderName & Fname)
Call IceNucleationTempCalc
' this is where i want the data from the sheet to be moved to the present workbook and sheet1
' and put it in different rows.. right now, the i cant march through the rows and the data keeps
' copied over and over on B4-K4. i know it is doing exactly what i am asking to do, but how to loop thru
' columns inside this while loop? if i use the i=4-6 is there a way to say .Range(B4, i)?
Sheets("IceNuclTemp").Range("F1:O1").Copy Destination:=Workbooks(currWorkBook).Sheets("Sheet1").Range("B4")
End With
Fname = Dir ' go to the next file in the folder
'Next i
Loop
End Sub
I feel like it is a simple thing i need to just change the way i am accessing those cells, but i cant figure it out.. Any help will be appreciated. thanks, Suresh.