excel - Trying to create a range from a set of values -


so have range of cells contains list of cell addresses.

enter image description here

column b & c show block of information starts , ends. column d states whether start of combination of tables, end of combination, or whether it's single table.

so having difficulty combining answers b & c form combined range. in picture, column e shows start a170 , end a596. (i don't think necessary tbh) need make range containing a170:a543, a548:a554, etc. , needs dynamic. these should create based on values in column d. i'm looking in vba, if it's easier in excel formulas, that's okay too.

can give me hints how accomplish this? brain mush.

you can create small user defined function (aka udf) stitch non-contiguous cell ranges textual representations of respective addresses. can return range native worksheet function uses cell range sum function or counta function (to use 2 simple examples).

function makenoncontiguousrange(startrngs range)     dim rng range, runion range      each rng in startrngs         if runion nothing             set runion = range(rng.value2, rng.offset(0, 1).value2)         else             set runion = union(runion, range(rng.value2, rng.offset(0, 1).value2))         end if     next rng      'debug.print runion.address     set makenoncontiguousrange = runion end function 

the function used on worksheet like,

=sum(makenoncontiguousrange(b2:b4)) 

in data sample writing,

=sum($a$170:$a$543,$a$548:$a$554,$a$558:$a$566) 

note passing in start of range in column b , gaining end range .offset. if need expand functionality pass in end range need check if both start , end ranges same size.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -