Solved

When do you need to Activate

Posted on 2014-03-15
4
185 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now