Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
worksheets
I found this in the help file:
Worksheets("Sheet1").Activate Do I need to use this .activate command and then this: with worksheets("sheet1") .range("A1") = "foo" .cells(2,1) = .range("A1") end with ....or can I just use this with command to activate whichever sheet I'm refering to? thanks. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
worksheets
Here is an interesting alternative...
If you didn't want to activate the sheet, you could try something like this: With Worksheets("Sheet1").Cells(1, 1) .Value = "foo" End With With Worksheets("Sheet1").Cells(2, 1) .Value = Sheets(1).Cells(1, 1).Value End With Mark Ivey "Charlie" wrote in message ... I found this in the help file: Worksheets("Sheet1").Activate Do I need to use this .activate command and then this: with worksheets("sheet1") .range("A1") = "foo" .cells(2,1) = .range("A1") end with ...or can I just use this with command to activate whichever sheet I'm refering to? thanks. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
worksheets
Or you could even simplify it a bit more....
With Worksheets("Sheet1") .Cells(1, 1).Value = "foo" .Cells(2, 1).Value = .Cells(1, 1).Value End With Mark Ivey "Mark Ivey" wrote in message ... Here is an interesting alternative... If you didn't want to activate the sheet, you could try something like this: With Worksheets("Sheet1").Cells(1, 1) .Value = "foo" End With With Worksheets("Sheet1").Cells(2, 1) .Value = Sheets(1).Cells(1, 1).Value End With Mark Ivey "Charlie" wrote in message ... I found this in the help file: Worksheets("Sheet1").Activate Do I need to use this .activate command and then this: with worksheets("sheet1") .range("A1") = "foo" .cells(2,1) = .range("A1") end with ...or can I just use this with command to activate whichever sheet I'm refering to? thanks. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
worksheets
No, but you are not actually activating the worksheet. In fact, you need not
The beauty of the with statement is that you don't activate. You should always avoid selection or activate unless absolutely necessary. It just slows things down. This is just fine. Just don't forget the dots. ...... If you only had one sub doit() with worksheets("sheet1") .range("A1") = "foo" .cells(2,1) = .range("A1") end with end sub If you only had one, forget with and just use sheets("sheet1").range("A1") = "foo" -- Don Guillett Microsoft MVP Excel SalesAid Software "Charlie" wrote in message ... I found this in the help file: Worksheets("Sheet1").Activate Do I need to use this .activate command and then this: with worksheets("sheet1") .range("A1") = "foo" .cells(2,1) = .range("A1") end with ...or can I just use this with command to activate whichever sheet I'm refering to? thanks. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Compare Rows on different Worksheets and Output Difference's to other Worksheets. | Excel Programming | |||
How use info in Excel shared worksheets to create new worksheets | Excel Worksheet Functions | |||
VBA / Macro for creating new worksheets and new columns from existing worksheets | Excel Programming | |||
Bypassing Worksheets when scanning worksheets for data | Excel Programming | |||
Need code to protect worksheets - amount of worksheets varies | Excel Programming |