ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba macro to define 3 files, and import columns (https://www.excelbanter.com/excel-programming/399223-vba-macro-define-3-files-import-columns.html)

Miree

vba macro to define 3 files, and import columns
 
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

Bernie Deitrick

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





All times are GMT +1. The time now is 12:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com