• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

help with excel macro programming

Rahul.Shankar

Junior Member
hi guys i got this program i am been doing. its a fairly simply program and i am fairly useless in programming🙄. I am beginning to learn program rite now and i am doing this problem


Qn) Develop a general code for multiplying an [m x n] matrix with any [n x k] matrix is
given below. Implement the code in EXCEL VB. Verify the results using hand
calculations
MATRIX A
1 2 3
3 4 4
2 0 6
MATRIX B
1 2
6 2
4 1

This is what i have done

Code:
Private Sub mycode_Click()
Dim i As Integer, j As Integer, n As Integer
Dim A() As Single, B() As Single, C() As Single
n = Cells(1, 2)
ReDim A(n, n) As Single, B(n, n) As Single, C(n, n) As Single

For i = 1 To n
    For j = 1 To n
        A(i, j) = Cells(1 + i, j)
    Next j
Next i

For i = 1 To n
    For j = 1 To n
        A(i, j) = Cells(2 + i, j)
    Next j
Next i

For i = 1 To n
    C(i) = 0#
    For j = 1 To n
        C(i) = C(i) + A(i, j) * B(j)
    Next j
Next i

For i = 1 To n
Cells(2 + i, n + 4) = C(i)
Next i
End Sub
can u guys see through my code and point out where i have gone wrong.
Thanks in advance
 
Last edited:
I don't completely understand what you're trying to do, but I'm guessing you think the "Cells" references are picking up values from the Excel spreadsheet. This will not work because you haven't specified a worksheet or range for the Cells property to reference. It needs to look something like this:

A(i,j) = Worksheets("Sheet1").Cells(i, j).Value

or:

A(i,j) = Range("InputArray"").Cells(i, j).Value

where InputArray is a named range in your spreadsheet.
 
Back
Top