I'm doing some fairly intensive searching for specific data on a sheet. So far it's involved filtering the sheet on several criteria, copying the visible rows to a TempWorksheet and then performing Range.Find looking for one of two possible values in these results. I've come across something peculiar I thought I'd share and get some opinions on.
The first .Find is looking for a specific value in a column/range ie:
Set rngRegion = .Range(B1:B6).Find(what:=strRegion, Lookin:=xlValues, Lookat:=xlWhole)
If this value is not found (rngRange is Nothing) another .Find is set off:
Set rngRegion = .Region(B1:B6).Find(what:=Empty, Lookin:=xlValues, Lookat:=xlWhole)
The business logic behind this is "Look in this table and see if we're supposed to do something with the equipment we've identified in our filtered results for this specific region (strRegion). If so, book it. If not found then look in that very same filtered dataset and see if we have a value of Empty in the Region column. Empty means we act on all 7 regions....not just this one. If we find it book them for ALL regions, otherwise we do nothing for this group and move on to the next".
After stepping the code and watching the TempWorkseet I find that if the first .Find fails and the second one is executed on a range where the FIRST occurance of region (.Cells(1,2).value) is Empty Excel returns the row for the SECOND. If however the first occurance is anywhere but Row 1 Excel returns the correct row#.
I've searched for a way to do some sort of reset on Find to clear any buffers that might be throwing off subsequent searches but I've come up empty. I've programmed around it for now but I'm real curious where the bug here is....Excel or me....
Any thoughts from the group?
The first .Find is looking for a specific value in a column/range ie:
Set rngRegion = .Range(B1:B6).Find(what:=strRegion, Lookin:=xlValues, Lookat:=xlWhole)
If this value is not found (rngRange is Nothing) another .Find is set off:
Set rngRegion = .Region(B1:B6).Find(what:=Empty, Lookin:=xlValues, Lookat:=xlWhole)
The business logic behind this is "Look in this table and see if we're supposed to do something with the equipment we've identified in our filtered results for this specific region (strRegion). If so, book it. If not found then look in that very same filtered dataset and see if we have a value of Empty in the Region column. Empty means we act on all 7 regions....not just this one. If we find it book them for ALL regions, otherwise we do nothing for this group and move on to the next".
After stepping the code and watching the TempWorkseet I find that if the first .Find fails and the second one is executed on a range where the FIRST occurance of region (.Cells(1,2).value) is Empty Excel returns the row for the SECOND. If however the first occurance is anywhere but Row 1 Excel returns the correct row#.
I've searched for a way to do some sort of reset on Find to clear any buffers that might be throwing off subsequent searches but I've come up empty. I've programmed around it for now but I'm real curious where the bug here is....Excel or me....
Any thoughts from the group?