+ Reply to Thread
Results 1 to 2 of 2

Help needed for creating array and writing formula in VBA, code included

  1. #1
    Registered User
    Join Date
    04-14-2012
    Location
    Austria
    MS-Off Ver
    Excel 2010
    Posts
    1

    Help needed for creating array and writing formula in VBA, code included

    Hello,

    I am trying to write a code to input a formula in VBA which returns a matrix, I am not too sure if the error is in the concatenation of the address or the creation of a matrix array.

    Help is much appreciated!

    Function linReg(y As Range, x As Range) As Variant

    Dim Anchor As Range
    Dim xRow As Integer
    Dim xCol As Integer
    Dim yRow As Integer

    Dim xColAddress As Integer

    xRow = x.Rows.Count
    xCol = x.Columns.Count
    yRow = y.Rows.Count

    xColAddress = xCol + 1

    Set Anchor = Worksheets("TakeHomeAssignmentQns2").Range("A1")

    If yRow = xRow Then

    Worksheets("TakeHomeAssignmentQns2").Range("B10:D15").FormulaArray = "=MMULT(MINVERSE(MMULT(TRANSPOSE(" & _
    Anchor.Cells(1, 2).Address & ":" & Anchor.Cells(xRow, xColAddress).Address & ");" & _
    Anchor.Cells(1, 2).Address & ":" & Anchor.Cells(xRow, xColAddress).Address & "));MMULT(TRANSPOSE(" & _
    Anchor.Cells(1, 2).Address & ":" & Anchor.Cells(xRow, xColAddress).Address & ");" & _
    Anchor.Cells(1, 9).Address & ":" & Anchor.Cells(yRow, 9).Address & "))"

    Else
    MsgBox "For function to work, number of rows in matrices x and y must be equal"
    End If

    End Function

  2. #2
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Help needed for creating array and writing formula in VBA, code included

    Please apply code tags to your code as per forum rules.

    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Select your code and click the [#] button at the top of the post window (if you are editing an existing post, press Go Advanced to see the [#] button).
    .?*??)
    `?.???.?*??)?.?*?)
    (?.?? (?.?
    Pichingualas <---
    ??????????????????????????

    Wrap your code with CODE TAGS.
    Thank those who helped you, Don't forget to add to their REPUTATION!!! (click on the star below their post).
    Please mark your threads as [SOLVED] when they are (Thread Tools->Mark thread as Solved).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1