Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract columns of differents workbooks in a macro with VBasic code?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm making a macro in excel with VBasic Code, and i need to extract different columns of different workbooks in a automatical way.

Please this answer will help me very much.

If you want to write me:
cesar_soto@
 
One idea

Sub Sample()
Dim xlApp As Object
Dim xlWB As Workbook
Dim WBPath As String
Dim WBName 'Array of Workbooks to open
Dim WSName 'Array of Worksheets to copy from
Dim cpyRnge 'Array of ranges to be copied
Dim pstRnge 'Array of ranges to be pasted to

Set xlApp = CreateObject("Excel.Application")
xlApp.AskToUpdateLinks = False
xlApp.DisplayAlerts = False
'xlApp.Visible = True
WBPath = "C:\Development\Excel\"
WBName = Array("Book1.xls", "Book2.xls")
WSName = Array("Sheet1", "Sheet1")
cpyRnge = Array("A1:A34", "B1:B35")
pstRnge = Array("A1", "B1")
For i = 0 To UBound(WBName)
Set xlWB = xlApp.Workbooks.Open(WBPath & WBName(i), False)
xlWB.Sheets(WSName(i)).Range(cpyRnge(i)).Copy
Sheets("Sheet1").Range(pstRnge(i)).Select
ActiveSheet.Paste
xlWB.Close
Next i

xlApp.AskToUpdateLinks = True
xlApp.DisplayAlerts = True
Set xlApp = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top