+ Reply to Thread
Results 1 to 8 of 8

Reading and writing a 40x40 matrix using VBA code

  1. #1
    Registered User
    Join Date
    02-20-2016
    Location
    Hong Kong, Hong Kong
    MS-Off Ver
    2016
    Posts
    10

    Reading and writing a 40x40 matrix using VBA code

    Hi again. Having written my first couple of basic VBA macros I'm back with a slightly more complex request. I'm still a novice so please treat me as such!

    I have a 40 by 40 matrix (so 1600 cells) which I want to read with vba code. I then want to write that same matrix back into my excel spreadsheet. Matrix contains numeric values.

    I'm hoping that there is a quick and easy way to do this and would really appreciate some code for reading the Matrix and putting it back into another location in the spreadsheet. I think I can work out the other code I need for my purpose if I can just get some help on how to read and write this Matrix.

    My goal is to perform multiple multiplication iterations (MMULT) on a Markov State to State Transition Matrix to reach a Steady State Matrix.

    As previously, I will be very grateful for any guidance.

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

    Re: Reading and writing a 40x40 matrix using VBA code

    Try something like this...

    Please Login or Register  to view this content.
    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.

  3. #3
    Registered User
    Join Date
    02-20-2016
    Location
    Hong Kong, Hong Kong
    MS-Off Ver
    2016
    Posts
    10

    Re: Reading and writing a 40x40 matrix using VBA code

    OK sounds great. Sorry for a very basic follow up question. How do I specify a range... so if I have a 20 by 20 matrix from A1 to U20, how would I do this?

    Sorry if this is basic. I have only just worked out how to read and write a single cell.

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

    Re: Reading and writing a 40x40 matrix using VBA code

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-20-2016
    Location
    Hong Kong, Hong Kong
    MS-Off Ver
    2016
    Posts
    10

    Re: Reading and writing a 40x40 matrix using VBA code

    and then
    Please Login or Register  to view this content.
    if I am writing back to same place? Any other code required or would these two lines be standalone? Sounds too easy!!

    Much appreciated!

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,271

    Re: Reading and writing a 40x40 matrix using VBA code

    Like this.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  7. #7
    Registered User
    Join Date
    02-20-2016
    Location
    Hong Kong, Hong Kong
    MS-Off Ver
    2016
    Posts
    10

    Re: Reading and writing a 40x40 matrix using VBA code

    Great many thanks! Extremely helpful. Worked a treat and now I'm starting to get it!

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,271

    Re: Reading and writing a 40x40 matrix using VBA code

    You're welcome and thanks for adding rep points.

+ 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. Automate reading or writing depending on the user
    By ploz in forum Excel General
    Replies: 1
    Last Post: 01-31-2016, 05:03 AM
  2. [SOLVED] Writing and reading datafiles
    By insomniac53 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-30-2015, 03:44 PM
  3. Reading/writing MP3 properties with Excel VBA
    By msrikanthjobs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-17-2012, 12:11 PM
  4. VBA Chart - Reading and Writing MajorGridlines
    By revector in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2008, 12:37 AM
  5. Reading / Writing to files
    By bobdylan75 in forum Excel General
    Replies: 1
    Last Post: 05-25-2008, 04:21 PM
  6. Problems with reading / writing ini-file
    By Youp in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-14-2006, 06:40 AM
  7. [SOLVED] Reading Writing Data from One WorkBook to Another
    By John Pierce in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-30-2005, 05:05 PM

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