Newbie question about iteration technique?

K

Karl Thompson

Given a fixed range, say A1:AD120.

The range is sorted by the contents of column "L" (which happens to get its
value by linking to a named range in other workbooks if that's important).
Column "L" can only hold one of three possible values, say "A", "B", and
"C".


The problem at hand is to write code that will return the row number that
contains the first instance of each value. There is not necessarily a value
"A".

Being a VBA novice, can someone please show me the most efficient way I
might do this? Do I have to iterate over each row?

TIA
 
T

Tom Ogilvy

Dim res as Variant
res = Application.Match("A",Range("L1:L120"),0)
if not iserror(res) then
rwA = res
end if
res = Applicaton.match("B",Range("L1:L120"),0)
if not iserror(res) then
rwB = res
end if
res = Application.match("C",Range("L1:L120"),0)
if not iserror(res) then
rwC = res
End if

Regards,
Tom Ogilvy
 
K

Karl Thompson

Thank you.


Tom Ogilvy said:
Dim res as Variant
res = Application.Match("A",Range("L1:L120"),0)
if not iserror(res) then
rwA = res
end if
res = Applicaton.match("B",Range("L1:L120"),0)
if not iserror(res) then
rwB = res
end if
res = Application.match("C",Range("L1:L120"),0)
if not iserror(res) then
rwC = res
End if

Regards,
Tom Ogilvy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top