Think I understand a bit of the code now. Following the process, the easiest way I see to do this to be to link ubound and lbound to a table so that it stops at the valve forward or backwards. Ideally I would like to have a column with locations of valves and the ubound and lbound would search for the next higher number (ubound) or lower (lbound). Not sure ubound or lbound can be a variable though?