Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
refer to range in another sheet | Excel Discussion (Misc queries) | |||
copied formulas refer to destination sheet not source sheet | Excel Worksheet Functions | |||
How can I refer to sheet number not sheet (name)? | Excel Worksheet Functions | |||
Refer new sheet to previous sheet | Excel Worksheet Functions | |||
Excel VBA (?!)-refer to a cell on Sheet to left of X, based on criteria on Sheet X | Excel Programming |