View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Create non-contiguius range "IF"

The general approach would be:

Sub MAKERANGEIF()
Dim rng as Range, rng1 as Range
Dim choice as Variant, cell as Range
Choice = "ABCD"
set rng = Range(Cells(1,1),Cells(rows.count,1).End(xlup))
for each cell in rng
if cell.Value = Choice then
if rng1 is nothing then
set rng1 = cell.offset(0,1)
else
set rng1 = Union(rng1, cell.offset(0,1))
end if
end if
Next
if not rng1 is nothing then
rng1.Name = "MyName"
end if
End Sub

If you really want a UDF, post back.

--
Regards,
Tom Ogilvy


"CLR" wrote in message
...
Hi All.......
If someone would be so kind, I need help to create a non-contiguious

range,
based on a similar principal to SUMIF........instead of summing the values
from the cells in column B adjacent to my selections in column A, I would
like to assemble all of the individual cells in column B into a
non-contiguious range and give it a RangeName. Sort of like....
=MAKERANGEIF(A:A,Choice,B:B)

Any guidance would be much appreciated..........

TIA
Vaya con Dios,
Chuck, CABGx3