Results 1 to 4 of 4

Math Help - Writing a macro for arrays

  1. #1
    Newbie
    Joined
    Dec 2012
    From
    Derry
    Posts
    8

    Writing a macro for arrays

    hey guys

    can someone give me a bit of advise on how to complete the below please

    "Write a macro in visual basic which:
    - Inputs the numbers for and populates a 2x2 array using a nested for next loop
    - Displays the matrix on screen with seperate line for row 2

    I have a macro that multiplys to arrays but i dont think its the right one.

    Sub multiply_arrays()

    Dim array1(1 To 2, 1 To 2), array2(1 To 2, 1 To 4), result

    '0 1
    '1 0

    array1(1, 1) = 0
    array1(1, 2) = 1
    array1(2, 1) = 1
    array1(2, 2) = 0

    ' 1 1 3 1
    ' 1 4 1 1

    array2(1, 1) = 1
    array2(1, 2) = 1
    array2(1, 3) = 3
    array2(1, 4) = 1
    array2(2, 1) = 1
    array2(2, 2) = 4
    array2(2, 3) = 1
    array2(2, 4) = 1

    result = WorksheetFunction.MMult(array1, array2)


    Range("A12").Select
    Selection.Value = result

    End Sub
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Sep 2012
    From
    Australia
    Posts
    4,163
    Thanks
    761

    Re: Writing a macro for arrays

    Hey seamy20.

    Are you just getting the entries for your matrix directly from a spreadsheet? If so, what is the routine to get the contents of a particular cell?
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Dec 2012
    From
    Derry
    Posts
    8

    Re: Writing a macro for arrays

    Im not to sure i just mannualy typed these numbers into the macro so it automatically displays them on thespreadsheet but i am a bit confused by the question, got really stuck at this question :-(
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Joined
    Sep 2012
    From
    Australia
    Posts
    4,163
    Thanks
    761

    Re: Writing a macro for arrays

    A for loop in VB looks something like:

    Dim MyArray(1 To 10, 1 To 10) As Double

    For i = 1 to 10
    For j = 1 to 10
    MyArray(i,j) = GetSpreadSheetCellNumber(i,j)
    Next j
    Next i

    As an example
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. macro economic maximization problem
    Posted in the Business Math Forum
    Replies: 1
    Last Post: February 17th 2011, 12:27 PM
  2. Macro-Economics questions
    Posted in the Business Math Forum
    Replies: 1
    Last Post: March 26th 2010, 08:17 PM
  3. can anybody help me with a macro economics question?
    Posted in the Business Math Forum
    Replies: 2
    Last Post: January 25th 2010, 08:17 AM
  4. How do I make a TI-89 macro?
    Posted in the Calculators Forum
    Replies: 5
    Last Post: November 9th 2009, 05:30 PM
  5. Macro--find Rate of Tech. Progress
    Posted in the Business Math Forum
    Replies: 0
    Last Post: October 13th 2009, 08:23 PM

Search Tags


/mathhelpforum @mathhelpforum