Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

When do you need to Activate

Posted on 2014-03-15
4
190 Views
Last Modified: 2014-03-15
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
Comment
Question by:upobDaPlaya
  • 2
  • 2
4 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 39931960
Always fully qualify your object references to avoid this problem:

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

Kevin
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 39931961
And do not use the Activate method unless absolutely necessary.

Kevin
0
 

Author Closing Comment

by:upobDaPlaya
ID: 39931992
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
 

Author Comment

by:upobDaPlaya
ID: 39931996
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question