PC Review


Reply
Thread Tools Rate Thread

define destination sheet

 
 
Darin Kramer
Guest
Posts: n/a
 
      20th Aug 2007
Help!!

My code below successfully opens a book from the right place, but now Im
trying to copy the sheet Results_first into the book which houses the
below macro, say book X.
How do I tell VB to paste the entire sheet into the book X..?

Regards

D


Dim i As Long, sName As String, sh As Worksheet
Dim dest As Range, bk As Workbook, bk1 As Workbook
Dim sh1 As Worksheet
Set bk1 = ThisWorkbook
i = 1

sName = Dir("\\server\_to_combine_files\*.xls")


Do While sName <> ""

Set bk = Workbooks.Open("\\server\_to_combine_files\" & sName)


Set sh = bk.Worksheets("Results_first")


*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWljaGFlbA==?=
Guest
Posts: n/a
 
      20th Aug 2007
sh.Copy Before:=Workbooks("X.xls").Sheets(1)

Change the Workbook and Sheet name to suit your needs.



--
If this posting was helpful, please click on the Yes button.
Regards,

Michael Arch.




"Darin Kramer" wrote:

> Help!!
>
> My code below successfully opens a book from the right place, but now Im
> trying to copy the sheet Results_first into the book which houses the
> below macro, say book X.
> How do I tell VB to paste the entire sheet into the book X..?
>
> Regards
>
> D
>
>
> Dim i As Long, sName As String, sh As Worksheet
> Dim dest As Range, bk As Workbook, bk1 As Workbook
> Dim sh1 As Worksheet
> Set bk1 = ThisWorkbook
> i = 1
>
> sName = Dir("\\server\_to_combine_files\*.xls")
>
>
> Do While sName <> ""
>
> Set bk = Workbooks.Open("\\server\_to_combine_files\" & sName)
>
>
> Set sh = bk.Worksheets("Results_first")
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
>

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      20th Aug 2007
Try:

sh.Copy Before:=ThisWorkbook.Sheets(1)


--
Hope that helps.

Vergel Adriano


"Darin Kramer" wrote:

> Help!!
>
> My code below successfully opens a book from the right place, but now Im
> trying to copy the sheet Results_first into the book which houses the
> below macro, say book X.
> How do I tell VB to paste the entire sheet into the book X..?
>
> Regards
>
> D
>
>
> Dim i As Long, sName As String, sh As Worksheet
> Dim dest As Range, bk As Workbook, bk1 As Workbook
> Dim sh1 As Worksheet
> Set bk1 = ThisWorkbook
> i = 1
>
> sName = Dir("\\server\_to_combine_files\*.xls")
>
>
> Do While sName <> ""
>
> Set bk = Workbooks.Open("\\server\_to_combine_files\" & sName)
>
>
> Set sh = bk.Worksheets("Results_first")
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
>

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      20th Aug 2007
or, if you want the copied sheet to be the last sheet in the workbook, like
this:

sh.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)

--
Hope that helps.

Vergel Adriano


"Vergel Adriano" wrote:

> Try:
>
> sh.Copy Before:=ThisWorkbook.Sheets(1)
>
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
> "Darin Kramer" wrote:
>
> > Help!!
> >
> > My code below successfully opens a book from the right place, but now Im
> > trying to copy the sheet Results_first into the book which houses the
> > below macro, say book X.
> > How do I tell VB to paste the entire sheet into the book X..?
> >
> > Regards
> >
> > D
> >
> >
> > Dim i As Long, sName As String, sh As Worksheet
> > Dim dest As Range, bk As Workbook, bk1 As Workbook
> > Dim sh1 As Worksheet
> > Set bk1 = ThisWorkbook
> > i = 1
> >
> > sName = Dir("\\server\_to_combine_files\*.xls")
> >
> >
> > Do While sName <> ""
> >
> > Set bk = Workbooks.Open("\\server\_to_combine_files\" & sName)
> >
> >
> > Set sh = bk.Worksheets("Results_first")
> >
> >
> > *** Sent via Developersdex http://www.developersdex.com ***
> >

 
Reply With Quote
 
Darin Kramer
Guest
Posts: n/a
 
      20th Aug 2007
Okay, that works... and how would I select all cells in the sheet,
instead of the whole work book..?
ie I now need to go back to source, select all cells, and then goto
destination and paste all cells....

Kind Regards
D



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      20th Aug 2007
to copy all cells from one worksheet and paste in another, try something like
this:

sh.Cells.Copy Destination:=ThisWorkbook.Sheets("Sheet1").Cells(1, 1)


--
Hope that helps.

Vergel Adriano


"Darin Kramer" wrote:

> Okay, that works... and how would I select all cells in the sheet,
> instead of the whole work book..?
> ie I now need to go back to source, select all cells, and then goto
> destination and paste all cells....
>
> Kind Regards
> D
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
TextToColumn when destination to other sheet CG Rosen Microsoft Excel Misc 4 17th Nov 2009 09:10 PM
copied formulas refer to destination sheet not source sheet Dantron Microsoft Excel Worksheet Functions 2 21st Oct 2009 09:51 PM
copying one entire row from a source sheet to a destination sheet Russ Microsoft Excel Programming 2 30th Sep 2009 07:16 PM
Copy/Paste Charts; Define Destination of Charts in PowerPoint ryguy7272 Microsoft Excel Programming 2 24th Jan 2008 08:04 PM
Copy every 3rd cell, define destination range for paste =?Utf-8?B?TWVsdGFk?= Microsoft Excel Programming 1 27th Sep 2006 01:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:58 PM.