Avatar of Jagwarman
Jagwarman
 asked on

is there a better way of saying

SearchRange = Range("A1", Range("A65536").End(xlUp))
For i = Range("E65536").End(xlUp).Row To 1 Step -1

so that I am not quoting numbers [65536 etc]

Thanks
Microsoft Excel

Avatar of undefined
Last Comment
Jagwarman

8/22/2022 - Mon
Phillip Burton

Instead of 65536 use:

activesheet.rows.count

Open in new window

Martin Liss

The problem with activesheet.rows.count is that for example in Excel 2010 it will give you a value of 1048576, so better would be Activesheet.usedrange.rows.count.
Jagwarman

ASKER
so how do I put this

SearchRange = Range("A1", Range("A65536").End(xlUp))
For i = Range("E65536").End(xlUp).Row To 1 Step -1

into rows count?
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Phillip Burton

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Phillip Burton

>> The problem with activesheet.rows.count is that for example in Excel 2010 it will give you a value of 1048576, so better would be Activesheet.usedrange.rows.count.

I assume that that is what Jagwarman wants - otherwise it's a very odd thing to have in Excel 2010.
Martin Liss

Well my point is that with activesheet.rows.count his search range will include most likely over a million blank rows, while withActivesheet.usedrange.rows.count the search range will be limited to the actual number of used rows.
Martin Liss

SearchRange = Activesheet.Usedrange.Rows.Count
For i = SearchRange To 1 Step -1

Note that this could be compressed to
For i = Activesheet.Usedrange.Rows.Count To 1 Step -1
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Jagwarman

ASKER
not sure why Martin but I can't get yours to to run I get type mismatch at this point

position = InStr(LCase(SearchRange(i, 1)), LCase(targetString))
Martin Liss

I'm sorry but I misread your original question and in my code SearchRange is a number (of rows) rather than a range, so my response to your question should have been.

SearchRange = Range("A1", Activesheet.usedrange.rows.count)
For i = Activesheet.usedrange.rows.count To 1 Step -1
Jagwarman

ASKER
Martin I am now getting
Method 'Range' of object '_Global' failed

Phillip Burton's works for me so I am going to accept his solution

But thanks for trying
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes