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. |
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. |
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. |
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. |
All times are GMT +1. The time now is 10:55 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com