Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Visual basic (combining wrkbks)

Hi,

I am currently using this piece of code:

Sub GetSheets()
Dim sPath As String, i As Long
Dim varr As Variant
Dim wkbk As Workbook
sPath = "H:\Work\metSLA\December\ResolverGroup\"
varr = Array("metslareportWE0512.xls", "metslareportWE1212.xls",
"metslareportWE191203.xls", "metslareportWE020104.xls")
For i = LBound(varr) To UBound(varr)
Set wkbk = Workbooks.Open(sPath & varr(i))
wkbk.Worksheets(1).Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)
wkbk.Close SaveChanges:=False
Next
End Sub

to combine the named files in the array into one workbook. However I
know very little about VB so am unable to edit this piece of code so
that all the combined workbooks are pasted into one worksheet as
opposed to separate ones. It must be very simple to merely append the
information to the end of the last paste but have been trying for a
while and getting a little dispondent!

For example if the first file used rows 1-200, then I want the second
file to fill from row 201 - end etc etc

Please help!!


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
rog rog is offline
external usenet poster
 
Posts: 39
Default Visual basic (combining wrkbks)

try this :

Sub GetSheets()
Dim sPath As String, i As Long
Dim varr As Variant
Dim wkbk As Workbook
Application.DisplayAlerts = False
sPath = "H:\Work\metSLA\December\ResolverGroup\"
varr = Array
("metslareportWE0512.xls", "metslareportWE1212.xls", "metsl
areportWE191203.xls", "metslareportWE020104.xls")

For i = LBound(varr) To UBound(varr)
Set wkbk = Workbooks.Open(sPath & varr(i))
wkbk.Worksheets(1).UsedRange.Copy
ThisWorkbook.ActiveSheet.Cells
(ThisWorkbook.ActiveSheet.UsedRange.Rows.Count + 2,
1).PasteSpecial
wkbk.Close SaveChanges:=False
Next
End Sub

Rgds

Rog

-----Original Message-----
Hi,

I am currently using this piece of code:

Sub GetSheets()
Dim sPath As String, i As Long
Dim varr As Variant
Dim wkbk As Workbook
sPath = "H:\Work\metSLA\December\ResolverGroup\"
varr = Array

("metslareportWE0512.xls", "metslareportWE1212.xls",
"metslareportWE191203.xls", "metslareportWE020104.xls")
For i = LBound(varr) To UBound(varr)
Set wkbk = Workbooks.Open(sPath & varr(i))
wkbk.Worksheets(1).Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)
wkbk.Close SaveChanges:=False
Next
End Sub

to combine the named files in the array into one

workbook. However I
know very little about VB so am unable to edit this piece

of code so
that all the combined workbooks are pasted into one

worksheet as
opposed to separate ones. It must be very simple to

merely append the
information to the end of the last paste but have been

trying for a
while and getting a little dispondent!

For example if the first file used rows 1-200, then I

want the second
file to fill from row 201 - end etc etc

Please help!!


---
Message posted from http://www.ExcelForum.com/

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Visual basic (combining wrkbks)

Fantastic - thanks very much! It leaves a gap of about 1400 blank rows
before pasting them in - not too much of a problem but if you know why
this is I would like to get rid of it but that code has done the trick
thanks for your time.


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
rog rog is offline
external usenet poster
 
Posts: 39
Default Visual basic (combining wrkbks)

The blank rows are because it finds the first empty row -
i guess the rows are not totally blank. If you think they
are, then delete them all before running the macro, and I
bet it will start in row 3.

Rgds

Rog



-----Original Message-----
Fantastic - thanks very much! It leaves a gap of about

1400 blank rows
before pasting them in - not too much of a problem but if

you know why
this is I would like to get rid of it but that code has

done the trick
thanks for your time.


---
Message posted from http://www.ExcelForum.com/

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Visual basic (combining wrkbks)

Thanks very much.


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Visual basic (combining wrkbks)

Sub GetSheets()
Dim sPath As String, i As Long
Dim varr As Variant
Dim wkbk As Workbook
sPath = "H:\Work\metSLA\December\ResolverGroup\"
varr = Array("metslareportWE0512.xls", "metslareportWE1212.xls",
"metslareportWE191203.xls", "metslareportWE020104.xls")
For i = LBound(varr) To UBound(varr)
Set wkbk = Workbooks.Open(sPath & varr(i))
wkbk.Worksheets(1).Range("A1").CurrentRegion.Copy _
Destination:=ThisWorkbook.Worksheets(1). _
Cells(rows.count,1).End(xlup)(2)
wkbk.Close SaveChanges:=False
Next
End Sub

--
Regards,
Tom Ogilvy


"ojj00u " wrote in message
...
Hi,

I am currently using this piece of code:

Sub GetSheets()
Dim sPath As String, i As Long
Dim varr As Variant
Dim wkbk As Workbook
sPath = "H:\Work\metSLA\December\ResolverGroup\"
varr = Array("metslareportWE0512.xls", "metslareportWE1212.xls",
"metslareportWE191203.xls", "metslareportWE020104.xls")
For i = LBound(varr) To UBound(varr)
Set wkbk = Workbooks.Open(sPath & varr(i))
wkbk.Worksheets(1).Copy After:=ThisWorkbook. _
Worksheets(ThisWorkbook.Worksheets.Count)
wkbk.Close SaveChanges:=False
Next
End Sub

to combine the named files in the array into one workbook. However I
know very little about VB so am unable to edit this piece of code so
that all the combined workbooks are pasted into one worksheet as
opposed to separate ones. It must be very simple to merely append the
information to the end of the last paste but have been trying for a
while and getting a little dispondent!

For example if the first file used rows 1-200, then I want the second
file to fill from row 201 - end etc etc

Please help!!


---
Message posted from http://www.ExcelForum.com/



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Visual basic (combining wrkbks)

Cheers Tom - worked great

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is Visual Basic the same as Visual Studio 2008? Mike Stewart Excel Worksheet Functions 5 January 11th 09 04:58 PM
In visual basic Chuck Excel Worksheet Functions 5 December 30th 07 03:08 PM
visual basic jiwolf Excel Worksheet Functions 2 October 8th 05 09:12 PM
changing the visual basic in office 2003 to visual studio net bigdaddy3 Excel Discussion (Misc queries) 1 September 13th 05 10:57 AM
Visual Basic 6.3 John S Malamon Excel Programming 2 August 11th 03 10:08 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"