+ Reply to Thread
Results 1 to 9 of 9

Insert rows based on count and fill rows with adjacent values

  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Insert rows based on count and fill rows with adjacent values

    Hi everyone,

    Hope I can get some help with this. Please see the description below and attached sample workbook.

    What I'm trying to do:

    What I'm trying to do is create a macro that will count the number of instances the values in Data column I appear, insert rows below the rows with alphanumeric strings containing the value in Summary column A, and then copy the Data column E values into these new rows if the corresponding column I values equal the searched value.

    Data

    This sheet contains the data that's going to be used to determine the # of rows that need to be inserted, where they are inserted, and what is to be copied into them.

    Summary

    This sheet contains alphanumeric strings in column A that contain a value found in column I of sheet1

    I have attached a sample workbook. Summary and Data sheets include sample data, and the Desired End Result worksheet is effectively the result I'm trying to reach. Please note, actual column E data in the Data worksheet will contain numbers and letters and will be entirely randomized. Also, Summary column A strings will be a bit longer than what is in the sample workbook.

    Any help?

    Thanks!!
    Attached Files Attached Files
    Last edited by Groovicles; 05-18-2015 at 03:58 PM. Reason: Sample workbook attached

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Insert rows based on count and fill rows with adjacent values

    I don't see an attachment

  3. #3
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Insert rows based on count and fill rows with adjacent values

    Hi Walrus and everyone else,

    Very sorry. Sample workbook is attached. Thanks for any help.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Insert rows based on count and fill rows with adjacent values

    Hi Groovicles,

    Try this:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Insert rows based on count and fill rows with adjacent values

    Hi xladept,

    Thanks very much. Your code appears to work perfectly on the sample workbook. I'll try and apply it to the actual workbook tomorrow. Thanks very much for your help!!

    Would it be too much trouble if explained the code to me? Specifically, I'm really get lost on this part:

    [CODE][/r = 2: Do Until ws.Cells(r, 1) = "": I = wd.Cells(r, 9)
    Do Until wd.Cells(r + n, 9) <> I: n = n + 1: Loop
    ws.Range("A" & r + 1 & ":A" & r + n - 1).Insert Shift:=xlDown
    r = r + n: n = 0
    CODE]

    What is r and n represent?

    Thanks
    Last edited by Groovicles; 05-18-2015 at 06:15 PM.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Insert rows based on count and fill rows with adjacent values

    Hi Groovicles,

    You're welcome and thanks for the rep!

    r is the row counter and n is the occurrence count

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Insert rows based on count and fill rows with adjacent values

    Hi xladept,

    Okay, but how does macro know what r = row counter and n = occurrence? Is that a built in definition for these two indicators in VBA? So for example, if I need to write a macro that requires occurrences to be tracked, would I always need to use n?

  8. #8
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Insert rows based on count and fill rows with adjacent values

    Hi xladept,

    I've tried the code on my actual workbook and I'm afraid it didn't work. All the code did was copy the results in E:E to the Summary page but did not sort them into the sections listed in the data page. The end result is that they are sorted by the 8 digit number in the A:A. Any ideas?

    Thanks,

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Insert rows based on count and fill rows with adjacent values

    Hi Groovicles,

    Sorry to hear that - I suspect the sample is somehow different than the actual workbook - can you post another more representative sample?

    The indices that you're asking about are incremented as the routine progresses with the n resetting to zero after each batch.

+ 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. Delete unwanted rows and update count of rows based on values
    By boddulus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-12-2015, 08:34 PM
  2. Insert rows based on a cell value and Fill down column A
    By blaxor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2014, 04:54 AM
  3. Count rows then insert formula based on row counts
    By midoop in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-09-2013, 11:17 AM
  4. I need to insert rows using macros, based on rows values. Please Help!
    By reservoirimgaging in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-19-2013, 02:13 PM
  5. Insert Rows Based on Cell Count
    By PY_ in forum Excel General
    Replies: 2
    Last Post: 10-29-2010, 10:52 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