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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,789
Messages
6,121,593
Members
449,038
Latest member
Arbind kumar

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