Macro to import data from another spreadsheet

InterNetWork

New Member
Joined
Dec 6, 2014
Messages
2
Hello,

Thanks to MrExcel MVP run the following sample code to get data from an external .xls file

Code:
Dim OpenFileName As StringDim wb As Workbook
'Select and Open workbook
OpenFileName = Application.GetOpenFilename("clients saved spreadsheet,*.xls")
If OpenFileName = "False" Then Exit Sub
Set wb = Workbooks.Open(OpenFileName)


'Get data EXAMPLE
ThisWorkbook.Sheets(1).Range("B5:C7").Value = wb.Sheets(1).Range("B5:C7").Value


MsgBox ("Done")


Set wb = Workbooks.Open(OpenFileName, UpdateLinks:=0)


How could i get data from an external .xls file specific columns (B,G,T,W,Y,Z,AA,AB,AD,AG,AT,AU,AX) and import them to "Master" Excel columns (A,B,C,D,E,F,G,H,I,J,K,L,M):confused:

Thank you for reading ... I would be very grateful for any help
Theodore
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
After digging the web and a bit-bite of code

Code:
Sub DataImport()Dim OpenFileName As String
Dim wb As Workbook
'Select and Open workbook
OpenFileName = Application.GetOpenFilename("clients saved spreadsheet,*.xls")
If OpenFileName = "False" Then Exit Sub
Set wb = Workbooks.Open(OpenFileName)


'Get data EXAMPLE
ThisWorkbook.Sheets(1).Range("$A$3:$A$100").Value = wb.Sheets(1).Range("$B$2:$B$100").Value
ThisWorkbook.Sheets(1).Range("$B$3:$B$100").Value = wb.Sheets(1).Range("$G$2:$G$100").Value
ThisWorkbook.Sheets(1).Range("$C$3:$C$100").Value = wb.Sheets(1).Range("$T$2:$T$100").Value
ThisWorkbook.Sheets(1).Range("$D$3:$D$100").Value = wb.Sheets(1).Range("$W$2:$W$100").Value
ThisWorkbook.Sheets(1).Range("$E$3:$E$100").Value = wb.Sheets(1).Range("$Y$2:$Y$100").Value
ThisWorkbook.Sheets(1).Range("$F$3:$F$100").Value = wb.Sheets(1).Range("$Z$2:$Z$100").Value
ThisWorkbook.Sheets(1).Range("$G$3:$G$100").Value = wb.Sheets(1).Range("$AA$2:$AA$100").Value
ThisWorkbook.Sheets(1).Range("$H$3:$H$100").Value = wb.Sheets(1).Range("$AB$2:$AB$100").Value
ThisWorkbook.Sheets(1).Range("$I$3:$I$100").Value = wb.Sheets(1).Range("$AD$2:$AD$100").Value
ThisWorkbook.Sheets(1).Range("$J$3:$J$100").Value = wb.Sheets(1).Range("$AG$2:$AG$100").Value
ThisWorkbook.Sheets(1).Range("$K$3:$K$100").Value = wb.Sheets(1).Range("$AT$2:$AT$100").Value
ThisWorkbook.Sheets(1).Range("$L$3:$L$100").Value = wb.Sheets(1).Range("$AU$2:$AU$100").Value
ThisWorkbook.Sheets(1).Range("$M$3:$M$100").Value = wb.Sheets(1).Range("$AX$2:$AX$100").Value


MsgBox ("Done")


ActiveWindow.Close
End Sub

ps: hope it works for you too :)
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top