vba macro to define 3 files, and import columns

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top