• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

When do you need to Activate

I had set wb = this workbook and
set ws = wb.sheets("orders")

i = application.CountA(Range("A":"A"))

This did not seem to provide the correct count unless I was in the orders worksheet.  Finally I did ws.activate and it worked fine.  2 questions

1 - When do you need to Activate
2 - Could I have avoided Activate by being explicit in my range selection......ws.range("A:A")

Don't yell at me I know I need to always explicitly name my range...I will..I just overlooked this range name somehow..
0
upobDaPlaya
Asked:
upobDaPlaya
  • 2
  • 2
1 Solution
 
zorvek (Kevin Jones)ConsultantCommented:
Always fully qualify your object references to avoid this problem:

i = Application.CountA(ws.Range("A":"A"))

Kevin
0
 
zorvek (Kevin Jones)ConsultantCommented:
And do not use the Activate method unless absolutely necessary.

Kevin
0
 
upobDaPlayaAuthor Commented:
thanks..i had a separate question where I learned the downfalls of activate, but was still a little foggy...it is defintely sinking in now..thanks for providing a great best practice foundation
0
 
upobDaPlayaAuthor Commented:
Ooops..that did not work..but I left out some information..further below I have

ws.range(D2:F7:).Select
selection.autofill destination:=Range("D2:F" & j)
......

I get select method of range class failed...

I assume you have to activate for a selection.  If so perhaps there is a better way of doing an autofill that does not involve a selection ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now