Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

When do you need to Activate

Posted on 2014-03-15
4
Medium Priority
?
197 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
[X]
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
  • 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

704 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