worksheets

  • Thread starter Thread starter Charlie
  • Start date Start date
C

Charlie

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.
 
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
 
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
 
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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top