+ Reply to Thread
Results 1 to 1 of 1

Trying to import data from a range of closed excel files

Hybrid View

  1. #1
    Registered User
    Join Date
    02-09-2014
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    1

    Trying to import data from a range of closed excel files

    Hi

    I have been trying to get this code to import data from a range of closed excel files in a folder and can't get it to work. I have modified codes form the web to pull in the data from one file - see below. But can't get it to loop through to grab it from a range of files. The data is in the same place in each file. There are approximately 50 files. The data is in a table that is 4 columns wide and 5 rows down, I need all the data to display in row 1 for the first set of data, then row 2 for the second and so on.

    Can you help???
    Option Explicit
    
    
    Sub GetDataDemo()
    
          Dim FilePath$, Row&, Column&, Address$
          
          'change constants & FilePath below to suit
          '***************************************
          Const FileName$ = "V5 iReport.xls"
          Const SheetName$ = "iTarget"
          Const NumRows& = 1
          Const NumColumns& = 4
          FilePath = ActiveWorkbook.Path & "\"
          '***************************************
          
          DoEvents
          Application.ScreenUpdating = False
          If Dir(FilePath & FileName) = Empty Then
                MsgBox "The file " & FileName & " was not found", , "File Doesn't Exist"
                Exit Sub
          End If
          Row = 1
                For Column = 1 To NumColumns
                      Address = Cells(Row, Column).Address
                      Cells(Row, Column) = GetData(FilePath, FileName, SheetName, Address)
                      Columns.AutoFit
                Next Column
           Row = 2
                For Column = 1 To NumColumns
                      Address = Cells(Row, Column).Address
                      Cells(Row - 1, Column + 4) = GetData(FilePath, FileName, SheetName, Address)
                      Columns.AutoFit
                Next Column
             Row = 3
                For Column = 1 To NumColumns
                      Address = Cells(Row, Column).Address
                      Cells(Row - 2, Column + 8) = GetData(FilePath, FileName, SheetName, Address)
                      Columns.AutoFit
                Next Column
             Row = 4
                For Column = 1 To NumColumns
                      Address = Cells(Row, Column).Address
                      Cells(Row - 3, Column + 12) = GetData(FilePath, FileName, SheetName, Address)
                      Columns.AutoFit
                Next Column
             Row = 5
                For Column = 1 To NumColumns
                      Address = Cells(Row, Column).Address
                      Cells(Row - 4, Column + 16) = GetData(FilePath, FileName, SheetName, Address)
                      Columns.AutoFit
                Next Column
          ActiveWindow.DisplayZeros = False
    End Sub
    
    Private Function GetData(Path, File, Sheet, Address)
          Dim Data$
          Data = "'" & Path & "[" & File & "]" & Sheet & "'!" & _
                Range(Address).Range("A1").Address(, , xlR1C1)
          GetData = ExecuteExcel4Macro(Data)
    End Function
    Last edited by vlady; 02-10-2014 at 07:56 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Import A specified Range From Closed Workbook (without opening and closing)
    By webboj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2013, 05:47 AM
  2. Need to copy range from multiple closed excel files
    By stretch90 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-22-2011, 03:37 PM
  3. Macro To Import Selected Range From Closed Workbook Only When Needed
    By jasono in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-28-2011, 06:48 PM
  4. Data import from .xls files into excel
    By booo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-05-2010, 06:19 PM
  5. Replies: 2
    Last Post: 05-30-2006, 07:55 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1