+ Reply to Thread
Results 1 to 9 of 9

VBA code to feed inputs row by row into a Excel modeller and generate corresponding output

  1. #1
    Registered User
    Join Date
    08-19-2015
    Location
    Toronto, Canada
    MS-Off Ver
    Microsoft 365
    Posts
    19

    VBA code to feed inputs row by row into a Excel modeller and generate corresponding output

    Hi All,

    I am sure the solution to my query below is some sort of VBA code but I am a complete novice with VBA so I desperately need your help!

    Here is a brief overview of my problem

    (1) I have a workbook with 2 tabs - Input/Output and Modeller. Input/Output tab contains list of records (in thousands of rows and each record has 3 fields/inputs) that need to be run (doing some calculations) in the Modeller tab one row at a time to generate results which need to be fed back to Input/Output tab.

    (2) How would I go about writing a VBA code to take each row of record (3 or more inputs per record), transfer inputs into modeller tab (where some calculations are done on the inputs), and then transfer the results (2 or more outputs per record) on same row as the corresponding inputs.

    I think it may involve a For loop but that is as far as I know....

    I have attached a small sample file to show you what I need help doing.

    Any help will be awesome and much appreciated!

    Thanks so much.

    Yusuf
    Attached Files Attached Files

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA code to feed inputs row by row into a Excel modeller and generate corresponding ou

    Try this on your data:-

    Please Login or Register  to view this content.
    Regards Mick
    Attached Files Attached Files
    Last edited by MickG; 11-10-2017 at 08:45 AM.

  3. #3
    Registered User
    Join Date
    08-19-2015
    Location
    Toronto, Canada
    MS-Off Ver
    Microsoft 365
    Posts
    19

    Re: VBA code to feed inputs row by row into a Excel modeller and generate corresponding ou

    Hi Mick,

    Thanks a tone for the quick response - code works! But here's the thing - the sample I attached was an over-simplification of actual modeller. In reality the formulae in modeller tab will be quite complex (referencing various other sheets) and I want to avoid writing all those in VBA.

    If possible I would prefer that the Modeller do the calculations and I use VBA for inputting data and exporting results after each run in modeller. How should the code change to achieve this?

    Thanks again.

    Cheers,

    Yusuf

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA code to feed inputs row by row into a Excel modeller and generate corresponding ou

    No problem.
    Replace the commandButton1.code with the below:-
    Please Login or Register  to view this content.
    Regards Mick

  5. #5
    Registered User
    Join Date
    08-19-2015
    Location
    Toronto, Canada
    MS-Off Ver
    Microsoft 365
    Posts
    19

    Re: VBA code to feed inputs row by row into a Excel modeller and generate corresponding ou

    Hi Mick - Marvelous! Works perfectly.

    You have saved me hours of work with your 2 examples of VBA code.

    Thanks a million!

    Cheers,

    Y

  6. #6
    Registered User
    Join Date
    08-19-2015
    Location
    Toronto, Canada
    MS-Off Ver
    Microsoft 365
    Posts
    19

    Re: VBA code to feed inputs row by row into a Excel modeller and generate corresponding ou

    Hi Mick,

    Sorry one more question...

    Does it matter whether I place the VBA code in specific sheet (i.e. InputOutput sheet) showing in project window or whether I insert a new Module in project window and add the code there.

    What is best practice for VBA programming? Do we need to use modules?

    Thanks,

    Y

  7. #7
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA code to feed inputs row by row into a Excel modeller and generate corresponding ou

    You can run the code wherever and however you like.
    As you will see from the code , the two specific sheets are named , therefore, wherever you run the code, those are the sheets the code will act on .
    I should use whatever suits you best. "CommandButton, Basic Module, shape" it's up to you .
    Regrds Mick

  8. #8
    Registered User
    Join Date
    08-19-2015
    Location
    Toronto, Canada
    MS-Off Ver
    Microsoft 365
    Posts
    19

    Re: VBA code to feed inputs row by row into a Excel modeller and generate corresponding ou

    Great. Thanks again.

  9. #9
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA code to feed inputs row by row into a Excel modeller and generate corresponding ou

    You're welcome

+ 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. Generate a value from three different inputs
    By jcavens in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-16-2017, 03:35 AM
  2. Auto generate email with that inputs excel spread
    By ckolawall in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2013, 04:02 PM
  3. Replies: 11
    Last Post: 07-14-2011, 09:21 PM
  4. Unable to feed output from one cell/sheet/file to another
    By pmarlow in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-18-2010, 01:53 PM
  5. Replies: 5
    Last Post: 07-15-2009, 03:32 PM
  6. Generate rss2.0 output from excel vba
    By okelly in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-19-2009, 07:24 AM
  7. Replies: 1
    Last Post: 05-11-2006, 08:10 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