PDA

View Full Version : Solved: Copy a subset of a named range using Union



Hamond
05-11-2010, 02:20 PM
Hi,

I am using the union comand to copy multiple named ranges from a worksheet.

Union(Range("oil"), Range("gold")).Copy

Where oil is named range covering column D, gold named range covering Column K.

But instead of copying the entire column, I would only like to copy a subset of of each named range/column, e.g rows 5 to 5000 in named range "oil" and same cells for "gold".

I know how to do this without using the named range by just selecting that range from each column but is it possible to do it using named ranges and if so what would the syntax look like?

FYI - I need to use named ranges because the columns move around and so I would have to change the code manually everytime new columns are inserting and deleted.

Thanks,

Hamond

p45cal
05-11-2010, 02:46 PM
range("myname").resize(4996).offset(4).Copy and/or:
For Each ar In Union(Range("oil"), Range("gold")).Areas
ar.Resize(4996).Offset(4).Select '.copy .whatever
Next ar