ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Newbie question about iteration technique? (https://www.excelbanter.com/excel-programming/271350-newbie-question-about-iteration-technique.html)

Karl Thompson

Newbie question about iteration technique?
 

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






Tom Ogilvy

Newbie question about iteration technique?
 
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

"Karl Thompson" wrote in message
...

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








Karl Thompson

Newbie question about iteration technique?
 
Thank you.


"Tom Ogilvy" wrote in message
...
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

"Karl Thompson" wrote in message
...

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











All times are GMT +1. The time now is 06:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com