+ Reply to Thread
Results 1 to 3 of 3

Macro that based on input, inserts X number of rows that fills with reference data

  1. #1
    Registered User
    Join Date
    10-13-2015
    Location
    Los Angeles, CA
    MS-Off Ver
    2013
    Posts
    2

    Smile Macro that based on input, inserts X number of rows that fills with reference data

    Hi!! Thanks in advance for any help!! For reference, I am using Excel 2013 on Windows 10.

    I'm trying to write a macro that inserts X amount of rows that populate with data from a matching set of rows on another sheet, with X being dynamically tied to the results of another reference cell. For example:

    If I enter K123 into cell B2, that will cause (based on an existing index/match formula) the value in cell G2 to change to "8". The macro will then add 8 rows (based on that resulting value in cell D10) which will fill with info based on matching the value in B2 to a set of data in another sheet.

    Likewise, if a code I enter into B3 results in a value of "3" in G3, the macro will add 3 rows which will fill with info based on matching the code in B3 to a set of data in another sheet.

    Illustrations of what I mean:

    On the main sheet, I would enter a quantity and code into column A & B. Each time I do, a result will populate in column G based on an existing index/match formula that tells me how many components that item has.

    Excel_Example1.png


    After entering K123 in B2, the macro should insert 8 rows based on the 8 that resulted in G2, and that data will fill from another worksheet as illustrated in the image after this one. Then, if I next enter K987 into B11, the macro will insert 3 rows based on the 3 that resulted in G11, that data also filling in from the same worksheet referenced after this image:

    Excel_Example2.png


    Reference worksheet:

    Excel_Example3.png

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Macro that based on input, inserts X number of rows that fills with reference data

    Welcome to the forum!

    There are at least 3 ways to do it. (1) Automate it when Component value in a new row is added, (2) run a macro for an existing list with Component values in each row as you show your 1st screen snip, (3) or run macro for a selected row if Component value exists.

    If you post a very short example like you show in your screen snips, it will make it easier to help. Click the Go Advance button in lower right of a reply, and then click the paperclip icon in toolbar to browse and attach XLSM file.

  3. #3
    Registered User
    Join Date
    10-13-2015
    Location
    Los Angeles, CA
    MS-Off Ver
    2013
    Posts
    2

    Re: Macro that based on input, inserts X number of rows that fills with reference data

    Thanks so much for the welcome!! I think my goal is to shoot for the first method you listed. I realized when I posted the first image that it wasn't clear that both lines of data wouldn't exist yet; as one line of data gets entered, if there is a resulting components value, the rows should automatically get added (so since row 2 has a components value, row 3 as it stands in the first picture couldn't exist because the desired macro would have added the eight lines of info desired below row 2; I would proceed with inputting the data currently in row 3 in picture 1 after the automated process for adding rows occured for the data in row 2, which would be inputted into row 11). I've attached what I was screenshotting from
    Example.xlsm
    Last edited by meehgz; 10-13-2015 at 05:13 PM.

+ 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. Need Macro that inserts two rows with data after value changes
    By KapitalD in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-29-2014, 11:03 PM
  2. Input todays date in a cell when an existing macro inserts a new row
    By alexander.small in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-05-2013, 11:35 AM
  3. Creating macro that inserts data into a cell based on certain critera
    By anjoseph9626 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-19-2013, 07:49 PM
  4. Replies: 1
    Last Post: 07-10-2012, 07:48 PM
  5. Macro based Import Data Inserts Cells, I want Replace
    By bramweisman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2005, 01:05 AM
  6. Replies: 1
    Last Post: 02-18-2005, 10:06 AM

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