Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create non-contiguius range "IF"
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create non-contiguius range "IF"
Hi Chuck,
Here is an example of one way, not name driven, but it works =SUMPRODUCT(SUMIF(INDIRECT({"B1","B4","B6","B8"}), "Choice",INDIRECT({"A1","A 4","A6","A8"}))) -- HTH Bob Phillips (remove nothere from email address if mailing direct) "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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create non-contiguius range "IF"
Just for interest,
Sum works as well - doesn't require Sumproduct -- Regards, Tom Ogilvy "Bob Phillips" wrote in message ... Hi Chuck, Here is an example of one way, not name driven, but it works =SUMPRODUCT(SUMIF(INDIRECT({"B1","B4","B6","B8"}), "Choice",INDIRECT({"A1","A 4","A6","A8"}))) -- HTH Bob Phillips (remove nothere from email address if mailing direct) "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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create non-contiguius range "IF"
As always.....your code is "Finer than frog hair"..........
Thanks Tom, Vaya con Dios, Chuck, CABGx3 "Tom Ogilvy" wrote: 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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create non-contiguius range "IF"
Thanks Bob, that's very interesting, and I'll for sure put it in my secret
stash for someday, but for this immediate reqirement, Tom hit the nail right on my head...... Vaya con Dios, Chuck, CABGx3 "Bob Phillips" wrote: Hi Chuck, Here is an example of one way, not name driven, but it works =SUMPRODUCT(SUMIF(INDIRECT({"B1","B4","B6","B8"}), "Choice",INDIRECT({"A1","A 4","A6","A8"}))) -- HTH Bob Phillips (remove nothere from email address if mailing direct) "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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Create Pivot Table Data with Column "Sum" rather than "count" defa | Excel Discussion (Misc queries) | |||
How do I create a "SUMIF" based upon a Date Range? | Excel Worksheet Functions | |||
Create pivot table, error "Range is not valid" | Charts and Charting in Excel | |||
create links to check boxes marked "good" fair"and "bad" | Excel Worksheet Functions | |||
use variable in Workbooks("book1").Worksheets("sheet1").Range("a1" | Excel Programming |