Matrix Dimension as variable/constant

gonurvia

New Member
Joined
Mar 29, 2017
Messages
13
Hello, I am trying to make a function which would use a matrix of (N ,2) dimensions. The function (incomplete) is as following:


PHP:
Function APPROACH(P1 As Range, x1 As Double, y1 As Double) As Double
N = P1.Rows.Count
Dim A1(1 To 3, 1 To 3) As Double
Dim A2(1 To [B]N[/B], 1 To 2) As Double


I get an error message which tells me N must be a constant. N is already defined as P1.Rows.Count and I won't change so, is there a way to change N from variable to constant? Also, I read something about matrices having a 32 dimension limit, is this true?


Thanks for the help!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hello, in fact N is not a constant. To make your code work, you'd need to use REd<code><code>im A2(1 To [B]N[/B], 1 To 2) As Double , when you use redim you can introduce variables.
Considering the dimensions limit, usually it's never wise to use more than 3 dimensions so you'd never find yourself in the situation of having so many dimensions, if you do then the code is not optimal.

</code></code>
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top