View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default vba macro to define 3 files, and import columns

Miree,

If the files are in the same folder, something like this, which copies 3 columns (A1:C10) from each
file and pastes them in B2:D11,E2:G11, and H2:J11, and on...

Sub OpenMultipleUserSelectedFiles()
Dim FileArray As Variant
Dim myBook As Workbook
Dim myTargetBook As Workbook
Dim mySht As Worksheet
Dim myCol As Integer

Set myTargetBook = ActiveWorkbook

myCol = 1

FileArray = Application.GetOpenFilename(MultiSelect:=True)
If IsArray(FileArray) Then
For i = LBound(FileArray) To UBound(FileArray)
Set myBook = Workbooks.Open(FileArray(i))
myBook.Worksheets(1).Range("A1:C10").Copy _
myTargetBook .Worksheets(1).Range("A2").Offset(0, myCol)
myCol = myCol + 3
myBook.Close False
Next i
End If
End Sub


--
HTH,
Bernie
MS Excel MVP


"Miree" wrote in message
...
I am new to the world of macros and vba
I need a code that allows a user to define three different files and import
some colums from each into a sheet set up to make graphs from the numbers.

Any help would be much appreciated