Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Refer to a lone sheet

Excel XP & Win XP
When a wb has only one sheet, the code name of that one sheet may not be
"Sheet1" if other sheets have been deleted.
If that wb is the active wb I can refer to that one sheet as "ActiveSheet".
My question comes when that workbook is not the active wb and I want to
paste into that one sheet. How do I refer to that one sheet to paste into
it, as in:
With wb.Sheets(???)
.range("A1").paste
End with
Thanks for your time. Otto


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Refer to a lone sheet

With wb.worksheets(1)


From the help file:
---------------------
Referring to Sheets by Index Number
See AlsoSpecificsAn index number is a sequential number assigned to a sheet,
based on the position of its sheet tab (counting from the left) among sheets
of the same type. The following procedure uses the Worksheets property to
activate worksheet one in the active workbook.

Sub FirstOne()
Worksheets(1).Activate
End Sub

If you want to work with all types of sheets (worksheets, charts, modules,
and dialog sheets), use the Sheets property. The following procedure
activates sheet four in the workbook.

Sub FourthOne()
Sheets(4).Activate
End Sub

Note The index order can change if you move, add, or delete sheets.


"Otto Moehrbach" wrote:

Excel XP & Win XP
When a wb has only one sheet, the code name of that one sheet may not be
"Sheet1" if other sheets have been deleted.
If that wb is the active wb I can refer to that one sheet as "ActiveSheet".
My question comes when that workbook is not the active wb and I want to
paste into that one sheet. How do I refer to that one sheet to paste into
it, as in:
With wb.Sheets(???)
.range("A1").paste
End with
Thanks for your time. Otto



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Refer to a lone sheet

with wb.worksheets(1)
or
with wb.sheets(1)

wb.sheets(1) is the leftmost sheet.

wb.worksheets(1) is the leftmost worksheet (chart sheets, macro sheets, dialog
sheets, ... could be further left).



Otto Moehrbach wrote:

Excel XP & Win XP
When a wb has only one sheet, the code name of that one sheet may not be
"Sheet1" if other sheets have been deleted.
If that wb is the active wb I can refer to that one sheet as "ActiveSheet".
My question comes when that workbook is not the active wb and I want to
paste into that one sheet. How do I refer to that one sheet to paste into
it, as in:
With wb.Sheets(???)
.range("A1").paste
End with
Thanks for your time. Otto


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Refer to a lone sheet

Ker, Dave
Thanks for the help. Otto
"Otto Moehrbach" wrote in message
...
Excel XP & Win XP
When a wb has only one sheet, the code name of that one sheet may not be
"Sheet1" if other sheets have been deleted.
If that wb is the active wb I can refer to that one sheet as
"ActiveSheet". My question comes when that workbook is not the active wb
and I want to paste into that one sheet. How do I refer to that one sheet
to paste into it, as in:
With wb.Sheets(???)
.range("A1").paste
End with
Thanks for your time. Otto



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Refer to a lone sheet

you've been given two alternatives, but activesheet still works even if the
workbook itself isn't teh active workbook.
you can't SELECT a cell in this activesheet if the book isn't active,but you
generally don't neeed cells to be selected in order to use them


so open a new excel instance, and add this code to book1
Sub test()
Workbooks("book1").ActiveSheet.Range("A1") = 1
End Sub

add a couple more books so that book2 or book3 is active. the code still
runs ok


"Otto Moehrbach" wrote:

Excel XP & Win XP
When a wb has only one sheet, the code name of that one sheet may not be
"Sheet1" if other sheets have been deleted.
If that wb is the active wb I can refer to that one sheet as "ActiveSheet".
My question comes when that workbook is not the active wb and I want to
paste into that one sheet. How do I refer to that one sheet to paste into
it, as in:
With wb.Sheets(???)
.range("A1").paste
End with
Thanks for your time. Otto





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Refer to a lone sheet

Patrick
Thanks for that. I didn't know that would work. I always thought
"ActiveSheet" could only be used with the active workbook. Otto
"Patrick Molloy" wrote in message
...
you've been given two alternatives, but activesheet still works even if
the
workbook itself isn't teh active workbook.
you can't SELECT a cell in this activesheet if the book isn't active,but
you
generally don't neeed cells to be selected in order to use them


so open a new excel instance, and add this code to book1
Sub test()
Workbooks("book1").ActiveSheet.Range("A1") = 1
End Sub

add a couple more books so that book2 or book3 is active. the code still
runs ok


"Otto Moehrbach" wrote:

Excel XP & Win XP
When a wb has only one sheet, the code name of that one sheet may not be
"Sheet1" if other sheets have been deleted.
If that wb is the active wb I can refer to that one sheet as
"ActiveSheet".
My question comes when that workbook is not the active wb and I want to
paste into that one sheet. How do I refer to that one sheet to paste
into
it, as in:
With wb.Sheets(???)
.range("A1").paste
End with
Thanks for your time. Otto





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
refer to range in another sheet Smallweed Excel Discussion (Misc queries) 5 November 13th 09 12:47 PM
copied formulas refer to destination sheet not source sheet Dantron Excel Worksheet Functions 2 October 21st 09 09:51 PM
How can I refer to sheet number not sheet (name)? DK Excel Worksheet Functions 2 March 30th 09 11:06 PM
Refer new sheet to previous sheet Spot Excel Worksheet Functions 2 September 9th 05 02:05 PM
Excel VBA (?!)-refer to a cell on Sheet to left of X, based on criteria on Sheet X tempjones Excel Programming 2 June 7th 04 09:48 PM


All times are GMT +1. The time now is 12:08 AM.

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

About Us

"It's about Microsoft Excel"