Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Index/Match range inside of For Each Selected worksheet

Posted on 2011-02-22
Medium Priority
Last Modified: 2012-05-11
set wb = workbooks.open(myFile)
for each wksht in wb.Worksheets
  for i = 2 to myCount
    wksht.Range("C1:T5000") ' This will actually be an index/match

Open in new window

Trying to figure out how to select a range inside of the for each loop of a set of worksheets. Need this for an index/match function that I'm creating, but I'm getting an "Object doesn't support this property or method" error.

Question by:keats88
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
LVL 22

Expert Comment

ID: 34956053
Did you try using the select method?


Of course, after you select, you'll need to do something with Selection or it will be a useless task.
LVL 37

Accepted Solution

TommySzalapski earned 500 total points
ID: 34956186
You cannot select a range on an inactive sheet. If you really want to select it you must to wksht.Activate first.
LVL 37

Expert Comment

ID: 34956194
You might need to activate the workbook too.

However, it is good practice to avoid selecting if you can (and you usually can).
LVL 22

Expert Comment

ID: 34956454
Agree with Tommy about selecting.  You can simply reference any cell you want with the Cells method, then the cells are not selected but you can read/write anything you want to them, even on other sheets.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

636 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