Consulting

Results 1 to 4 of 4

Thread: Array raising each element to a power - please help!

  1. #1
    VBAX Newbie
    Joined
    Sep 2012
    Posts
    2
    Location

    Array raising each element to a power - please help!

    Hi, I have written code which creates an array of 100 elements and then each element is an input matrix (Min) which the user enters into the worksheet raised to a power. I think the logic to the code is right as it keeps on calling the MMult function however I get the error 'Run-time error 1004' Unable to get the MMult property from the Worksheet Function.

    Can anyone please let me know what I am doing wrong?

     
    Dim oS(99) As Variant
    Dim x As Variant
    Dim power As Integer
    Dim Min As Variant
     
    power = 5 'This is the power to which I'd like the elements of the array raised to
     
    Min = Range(Worksheets("1").Cells(3, 3), Worksheets("1").Cells(8, 8))  'This is the matrix that the user enters into the specified worksheet range 
     
    For x = 1 To 99    
        oS(x) = WorksheetFunction.MMult(oS(x), Min)
    Next
    Thanks,
    Ana x

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    [VBA]Sub snb()
    Range("C3:H8").Offset(10) = [index(C3:H8^5,)]
    End Sub[/VBA]

  3. #3
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    @ana
    The number of columns in array1 must be the same as the number of rows in array2, and both arrays must contain only numbers.
    Array1 and array2 can be given as cell ranges, array constants, or references.
    MMult returns the #VALUE! error when:
    Any cells are empty or contain text.
    The number of columns in array1 is different from the number of rows in array2.
    The size of the resulting array is equal to or greater than a total of 5,461 cells.

    @snb
    can you explain me your very good code ?

  4. #4
    VBAX Newbie
    Joined
    Sep 2012
    Posts
    2
    Location
    @ patel

    Thank you very much for your help! I figured out my problem it was because the array oS(x) was empty so you were right. I just entered in

     
    oS(x) = Min
    In the code and it filled array with the input matrix and was then able to raise it to a power.

    @ snb I didn't quite understand what your code meant but thank you for the help anyway

    Ana x

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •