Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2. Sub import_data()
  3. Dim wbMain As Workbook, wbSource As Workbook 'setting workbooks
  4. Dim wsMain As Worksheet, wsSource As Worksheet 'setting worksheets
  5. Dim intRow As Integer, j As Integer 'row count + iterator
  6. 'FSO variables
  7. Dim objFSO As FileSystemObject
  8. Dim objFolder As Folder
  9. Dim objFile As File
  10. Dim strPath As String 'string with path to folder containing files
  11.  
  12. Application.ScreenUpdating = False
  13.  
  14. strPath = "C:\Users\Usser\Desktop\excel task"
  15. Set objFSO = CreateObject("Scripting.FileSystemObject")
  16. Set objFolder = objFSO.GetFolder(strPath)
  17. Set wbMain = ActiveWorkbook
  18. Set wsMain = wbMain.Sheets(1)
  19.  
  20. intRow = 2
  21. For Each objFile In objFolder.Files
  22. If objFile.Name <> wbMain.Name Then
  23. Set wbSource = Workbooks.Open(objFile.Path)
  24. Set wsSource = wbSource.Sheets(1)
  25. For j = 2 To 20 Step 2
  26. wsMain.Cells(intRow, j / 2).Value = wsSource.Cells(15, j).Value
  27. Next j
  28. wsMain.Cells(intRow, 11).Value = objFile.Name
  29. wbSource.Close
  30. intRow = intRow + 1
  31. End If
  32. Next objFile
  33.  
  34. Application.ScreenUpdating = True
  35.  
  36.  
  37. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement