Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Sub import_data()
- Dim wbMain As Workbook, wbSource As Workbook 'setting workbooks
- Dim wsMain As Worksheet, wsSource As Worksheet 'setting worksheets
- Dim intRow As Integer, j As Integer 'row count + iterator
- 'FSO variables
- Dim objFSO As FileSystemObject
- Dim objFolder As Folder
- Dim objFile As File
- Dim strPath As String 'string with path to folder containing files
- Application.ScreenUpdating = False
- strPath = "C:\Users\Usser\Desktop\excel task"
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objFolder = objFSO.GetFolder(strPath)
- Set wbMain = ActiveWorkbook
- Set wsMain = wbMain.Sheets(1)
- intRow = 2
- For Each objFile In objFolder.Files
- If objFile.Name <> wbMain.Name Then
- Set wbSource = Workbooks.Open(objFile.Path)
- Set wsSource = wbSource.Sheets(1)
- For j = 2 To 20 Step 2
- wsMain.Cells(intRow, j / 2).Value = wsSource.Cells(15, j).Value
- Next j
- wsMain.Cells(intRow, 11).Value = objFile.Name
- wbSource.Close
- intRow = intRow + 1
- End If
- Next objFile
- Application.ScreenUpdating = True
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement