#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default 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
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
Compare Rows on different Worksheets and Output Difference's to other Worksheets. [email protected] Excel Programming 3 September 19th 07 04:48 PM
How use info in Excel shared worksheets to create new worksheets dkc Excel Worksheet Functions 0 June 28th 07 08:36 PM
VBA / Macro for creating new worksheets and new columns from existing worksheets webby2006 Excel Programming 3 July 25th 06 03:38 PM
Bypassing Worksheets when scanning worksheets for data Jig Bhakta Excel Programming 3 April 7th 06 03:45 PM
Need code to protect worksheets - amount of worksheets varies Sandy[_3_] Excel Programming 1 September 9th 03 02:17 AM


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