Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting too many rows

Status
Not open for further replies.

alwayslrN

IS-IT--Management
Jun 20, 2006
159
US
I have a macro that opens a file and then based on specified fields in the header (row 1) executes another macro. This one particular macro has 4 files that use it and one of those files only has two rows, the header and a row with data. For this particular file when

Code:
Windows(LoadName).Activate
Range("I2").Select

is executed, it selects the data in row 2 and all the way down to the last row in the worksheet. This causes issues in a later macro in that I loop through all the values in the range and return another value. Thing is, it not only does it for the cell with data, but also for all the other cells from row3 down to 65536.

What is the best way to keep this from happening?

Thanks
 
I'm sorry but I can't duplicate your problem. When I run the code, it correctly selects I2. You could try:

Application.Goto Range("I2")

I doubt it will help but maybe.

Trisha
padinka@yahoo.com
 
I did not do a good job of explaining the issue, I forgot to add a very important line of code.

Say we have the following

A B C
12 run this

The

Code:
Window(LoanName).Activate
Range("A2").Select

Is followed by

Code:
Range(Selection,Selection.End(xlDown)).Select

As a result of the above, I get the issue described in the first post. I need to avoid that issue, but at the same time since other files have more than one row after the header I still need the above code.

Thanks
 
Would this help:
Code:
Window(LoanName).Activate
Range("A2").Select
Range(Selection,Range("A65536").End(xlUp)).Select

... I'm sure this have been covered hundreds of times before, and that my solution is one of many possible solutions.

By the way, you don't need to use Select for most coding, and that simplifies your code and also speeds it up.

Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top