View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis[_5_] Dana DeLouis[_5_] is offline
external usenet poster
 
Posts: 77
Default union method for non-adjacent ranges

However, apparently the union statement cannot combine non-
adjacent ranges, but only adjacent ranges.


I believe that each argument to the MMult function requires a range with 1
area. It can not be two or more separate areas, even if the combined area
has the look of 1 area.
For an example, do a simple MMult on A2:A4, and B1:D1, but give the range
A2:A4 a range name like "xx".
Your function should work. Now, change the definition of "xx" to a range =
A2:A3,A4
Basically it's the same area, and it's the same cells. However, this has 2
areas, and therefore won't work.
Therefore, by using Union, you will have two areas, and this creates a
problem.
If you can combine them into 1 area, either as an array, or Range Name
formula, perhaps something similar to...

With Application.WorksheetFunction
[A1:C3] = .MMult(.Transpose(Array(1, 2, 3)), Array(4, 5, 6))
End With

--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"felix" wrote in message
...
Hi there,

I am trying to combine two non-adjacent ranges. The
resulting range shall then be multiplied with another
range created the same way using the mmult worksheet
function.
However, apparently the union statement cannot combine non-
adjacent ranges, but only adjacent ranges.
I am running into this problem because I need to perform
matrix calculations with a matrix exceeding the 256
columns a worksheet provides.

Any help will be greatly appreciated!
Felix

Code

Note: a and cd are column ranges, b and ef are row ranges

Dim Result As Range
Set Result = Range("Result")
Dim a, b, cd, ef, acd, bef As Variant

Set a = Range("a")
Set b = Range("b")
Set cd = Range("cd")
Set ef = Range("ef")

acd = Union(a, cd)
bef = Union(b, ef)

Result = Application.WorksheetFunction.MMult(bef, acd)

End Sub