treyabrown
New Member
- Joined
- May 23, 2014
- Messages
- 7
Can someone help me fix my code. I am trying to loop through a column that has numbers beside each of the new files. For each i it should set the range as an offset 2 columns over and pull that file name, but when it loops through I get a runtime error '91'
Then at the bottom I am trying to loop through each of the new file names and move it over to the column "already uploaded" so they don't show as new the next time it is run.
Sub UploadNewData()
Dim FileName As Range
Dim FullFileName As String
ActiveWorkbook.Sheets("Comparison").Select
For i = 1 To Range("NewFiles")
FileName = Range("F:F").Find(What:=i, LookIn:=xlValues).Offset(0, -2)
FullFileName = Range("FilePath") & FileName
ChDir (Range("FilePath"))
Workbooks.Open FileName:=FullFileName
Cells.Select
Selection.Copy
Sheets("Raw Data").Select
Cells.Select
ActiveSheet.Paste
Next i
ActiveWorkbook.Sheets("Comparison").Select
For i = 1 To Range("NewFiles")
Set FileName = Range("F:F").Find(What:=i, LookIn:=xlValues).Offset(0, -2)
FileName.Copy
Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Next i
ActiveWorkbook.Save
End Sub
Then at the bottom I am trying to loop through each of the new file names and move it over to the column "already uploaded" so they don't show as new the next time it is run.
Sub UploadNewData()
Dim FileName As Range
Dim FullFileName As String
ActiveWorkbook.Sheets("Comparison").Select
For i = 1 To Range("NewFiles")
FileName = Range("F:F").Find(What:=i, LookIn:=xlValues).Offset(0, -2)
FullFileName = Range("FilePath") & FileName
ChDir (Range("FilePath"))
Workbooks.Open FileName:=FullFileName
Cells.Select
Selection.Copy
Sheets("Raw Data").Select
Cells.Select
ActiveSheet.Paste
Next i
ActiveWorkbook.Sheets("Comparison").Select
For i = 1 To Range("NewFiles")
Set FileName = Range("F:F").Find(What:=i, LookIn:=xlValues).Offset(0, -2)
FileName.Copy
Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Next i
ActiveWorkbook.Save
End Sub