Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default A Sheet by any other name.....

Hi All........
I am opening a second Excel file and copying the only sheet therein back to
my original file. All code works fine, except that it requires me to
hardcode the SheetName of the second file. I would like to be able to
retrieve the sheet regardless of what it might be named.

Here's what I'm using now

Sheets("BUYER_CB").Select
Sheets("BUYER_CB").Copy After:=ThisWorkbook.Sheets(1)


TIA for any assistance
Vaya con Dios,
Chuck, CABGx3



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default A Sheet by any other name.....

One way:

Sheets(1).Copy After:=ThisWorkbook.Sheets(1)

Note that the first line isn't required.


In article ,
CLR wrote:

Hi All........
I am opening a second Excel file and copying the only sheet therein back to
my original file. All code works fine, except that it requires me to
hardcode the SheetName of the second file. I would like to be able to
retrieve the sheet regardless of what it might be named.

Here's what I'm using now

Sheets("BUYER_CB").Select
Sheets("BUYER_CB").Copy After:=ThisWorkbook.Sheets(1)


TIA for any assistance
Vaya con Dios,
Chuck, CABGx3

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default A Sheet by any other name.....

Does the 2nd workbook have more than one worksheet?

If it only has one worksheet then the sheet should be the active sheet.

instead of this
Sheets("BUYER_CB").Select
Sheets("BUYER_CB").Copy After:=ThisWorkbook.Sheets(1)

oldsheetname = activeworksheet.name
newsheetname = activesheet.anme
sheets(newsheetname).select
sheets(newsheetname).copy after:=thisworkbook.sheets(oldsheetname)


"CLR" wrote:

Hi All........
I am opening a second Excel file and copying the only sheet therein back to
my original file. All code works fine, except that it requires me to
hardcode the SheetName of the second file. I would like to be able to
retrieve the sheet regardless of what it might be named.

Here's what I'm using now

Sheets("BUYER_CB").Select
Sheets("BUYER_CB").Copy After:=ThisWorkbook.Sheets(1)


TIA for any assistance
Vaya con Dios,
Chuck, CABGx3



  #4   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default A Sheet by any other name.....

Thanks JE..........so simple even I can understand it........and it works!

Vaya con Dios,
Chuck, CABGx3



"JE McGimpsey" wrote:

One way:

Sheets(1).Copy After:=ThisWorkbook.Sheets(1)

Note that the first line isn't required.


In article ,
CLR wrote:

Hi All........
I am opening a second Excel file and copying the only sheet therein back to
my original file. All code works fine, except that it requires me to
hardcode the SheetName of the second file. I would like to be able to
retrieve the sheet regardless of what it might be named.

Here's what I'm using now

Sheets("BUYER_CB").Select
Sheets("BUYER_CB").Copy After:=ThisWorkbook.Sheets(1)


TIA for any assistance
Vaya con Dios,
Chuck, CABGx3


  #5   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default A Sheet by any other name.....

Thanks for the response Joel, but I'm using JE's one-liner for now. Your's
is interesting tho, and may prove useful for another application I'm thinking
of....
Thanks again

Vaya con Dios,
Chuck, CABGx3



"Joel" wrote:

Does the 2nd workbook have more than one worksheet?

If it only has one worksheet then the sheet should be the active sheet.

instead of this
Sheets("BUYER_CB").Select
Sheets("BUYER_CB").Copy After:=ThisWorkbook.Sheets(1)

oldsheetname = activeworksheet.name
newsheetname = activesheet.anme
sheets(newsheetname).select
sheets(newsheetname).copy after:=thisworkbook.sheets(oldsheetname)


"CLR" wrote:

Hi All........
I am opening a second Excel file and copying the only sheet therein back to
my original file. All code works fine, except that it requires me to
hardcode the SheetName of the second file. I would like to be able to
retrieve the sheet regardless of what it might be named.

Here's what I'm using now

Sheets("BUYER_CB").Select
Sheets("BUYER_CB").Copy After:=ThisWorkbook.Sheets(1)


TIA for any assistance
Vaya con Dios,
Chuck, CABGx3



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
excel sheet bootom half sheet goes behind top part of sheet rob Excel Worksheet Functions 2 January 17th 09 01:28 AM
Duplicate sheet, autonumber sheet, record data on another sheet des-sa[_2_] Excel Worksheet Functions 0 May 8th 08 06:56 PM
Export sheet store sheet import sheet. Robert[_33_] Excel Programming 0 December 28th 06 01:58 PM
relative sheet references ala sheet(-1)!B11 so I can copy a sheet. RonMc5 Excel Discussion (Misc queries) 9 February 3rd 05 12:51 AM
Inserting a row in sheet A should Insert a row in sheet B, removing a row in Sheet A should remove the corresponding row in sheet B Hannes Heckner Excel Programming 1 March 5th 04 09:10 AM


All times are GMT +1. The time now is 07:50 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"