+ Reply to Thread
Results 1 to 6 of 6

Printing matrix to worksheet

  1. #1
    Registered User
    Join Date
    01-23-2016
    Location
    Toronto, Canada
    MS-Off Ver
    Mac MS Office 2016
    Posts
    3

    Printing matrix to worksheet

    Hello everyone,

    I've been trying to learn VBA for just over a week now, and I need some help with a class assignment. The assignment asks to manually add 2 matrices together and to print the result onto a worksheet.

    I have made a function to add the 2 matrices, and a subroutine to input the matrices and print the result onto a worksheet. From my novice POV I can't find anything wrong with what I've done except that the function or subroutine doesn't work.

    I would be very grateful if someone could check my code and tell me what's wrong with it. Also, I would love to receive feedback about what I've done so far - is the code written clearly? is it unnecessarily complicated? etc. Thanks to everyone in advance.

    assignment012-arrayADD.xlsm
    Last edited by codebreaker3; 01-24-2016 at 03:20 PM. Reason: Clarity

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Printing matrix to worksheet

    I have cleared most of your errors.

    your code is quite clear so congrats on that.

    You forgot to write the code to add the matrices together.

    If you are in explicit mode all your variables must be defined

    You cannot define and set a variable in one line

    Your sheetnames must be in quotation marks unless they are held in variables.

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Printing matrix to worksheet

    The not-so-obvious issue that's holding you up is VBA doesn't like a code module and function to be named the same. So change either the code module name or the function name so they are different.

    There are other issues with the code which I'll let you work out. One basic one is you haven't passed the result to the Function name. At some point in your code you'll need...
    addmatrix = the calculated results
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    01-23-2016
    Location
    Toronto, Canada
    MS-Off Ver
    Mac MS Office 2016
    Posts
    3

    Re: Printing matrix to worksheet

    Thanks very much for the corrections. I thought the function addMatrix should suffice? :

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-23-2016
    Location
    Toronto, Canada
    MS-Off Ver
    Mac MS Office 2016
    Posts
    3

    Re: Printing matrix to worksheet

    Thanks for the reply. I've added to code you said, but whenever I try to test only the function the answer I get is 0. What sort of issues are there with the function code? Is there anything wrong with the procedure? or is the problem with the syntax?

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Printing matrix to worksheet

    Look at this page.

    http://stackoverflow.com/questions/2...-to-add-arrays

    There is a neat solution that uses paste special to sum two arrays, but that is not a manual solution and is no good to you

    It also shows a second solution using two nested loops to sum the arrays.

    Two more things your code does not address is what happens if the user presses cancel or aborts an input box.

    Also what happens if the arrays specified by the user are not the same size.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. To copy printing area of one worksheet to worksheet in a different workbook
    By sneha1889 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2014, 04:04 AM
  2. Replies: 2
    Last Post: 02-11-2014, 05:05 AM
  3. Covariance matrix from worksheet
    By uncina in forum Excel Programming / VBA / Macros
    Replies: 28
    Last Post: 01-22-2014, 12:17 PM
  4. Replies: 0
    Last Post: 09-18-2013, 06:34 AM
  5. [SOLVED] Printing labels on a dot matrix via Excel
    By sdrais in forum Excel General
    Replies: 1
    Last Post: 07-20-2006, 05:55 PM
  6. Printing labels on a dot matrix printer - what does this code do
    By Laurence Lombard in forum Excel General
    Replies: 2
    Last Post: 06-19-2006, 08:25 AM
  7. Printing labels on a dot matrix printer - what does this code do
    By Laurence Lombard in forum Excel General
    Replies: 0
    Last Post: 06-18-2006, 02:25 AM

Tags for this Thread

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