+ Reply to Thread
Results 1 to 10 of 10

If partial string = "dup" is in Column A, insert a row below that cell.

  1. #1
    Registered User
    Join Date
    01-15-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    If partial string = "dup" is in Column A, insert a row below that cell.

    Example with Expected Outcome.xlsxExample with Expected Outcome.xlsxI'm trying to piece a bit of code together from different solutions I've come across. What I have runs but doesn't insert rows. What did I do wrong?

    Please Login or Register  to view this content.
    Once I get this worked out, I'm trying to piece the code together that will find the max in Col. B from the two rows above the new row, and place the value in the new row, Col. B. Additionally, I want it to concatenate the original text containing the "dup" with "_max" in Col. A of the new row. I can do this manually, but there are ~50 of these "dup" rows.
    Last edited by Niedermee; 01-21-2014 at 07:18 PM.

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: If partial string = "dup" is in Column A, insert a row below that cell.

    try this:
    Please Login or Register  to view this content.
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: If partial string = "dup" is in Column A, insert a row below that cell.

    Hello Niedermee,

    Here is another method. The assumptions are column "C" is empty, the row below the last row with data is empty, and the data is in ascending order as shown.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    01-15-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: If partial string = "dup" is in Column A, insert a row below that cell.

    Thanks, Pierre. It works, but only if I use the data just as presented. My real data has many more columns than just the two I provided in the example dataset and it gives me an error '13', Type Mismatch.
    When I click on debug the following code is highlighted yellow:

    Then M_ax = ActiveCell.Offset(i, 1)

    -P.

  5. #5
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: If partial string = "dup" is in Column A, insert a row below that cell.

    Hi -

    Also try this one;
    Please Login or Register  to view this content.
    event

  6. #6
    Registered User
    Join Date
    01-15-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: If partial string = "dup" is in Column A, insert a row below that cell.

    If I have spaces in my dataset, meaning blank rows between groups, will this cause problems?

    -P.

  7. #7
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: If partial string = "dup" is in Column A, insert a row below that cell.

    to Event21,
    something is wrong in your MAX function.
    WorksheetFunction.Max(r.Offset(-1, 1).Resize(2))

    Resize and Offset should be variable too.

    This modification seems to work:
    Please Login or Register  to view this content.
    I really learned something with your code Event21. I was looking for something like this, but it seems to be out of reach for me.
    Thanks
    Last edited by p24leclerc; 01-21-2014 at 09:41 PM.

  8. #8
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: If partial string = "dup" is in Column A, insert a row below that cell.

    Quote Originally Posted by p24leclerc View Post
    to Event21,
    something is wrong in your MAX function.
    WorksheetFunction.Max(r.Offset(-1, 1).Resize(2))

    Resize and Offset should be variable too.

    This modification seems to work:
    Please Login or Register  to view this content.
    I really learned something with your code Event21. I was looking for something like this, but it seems to be out of reach for me.
    Thanks
    so if you run your modified code, you will get;
    Please Login or Register  to view this content.
    the sample from -P. on this red portion = MW-04-dup 25

    If I have spaces in my dataset, meaning blank rows between groups, will this cause problems?
    no as long as the space row is not covered by the two cells above the "dup" cell

    let us see the test results from -P.

    event

  9. #9
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: If partial string = "dup" is in Column A, insert a row below that cell.

    Sorry, I did not properly read the OP requirements. Event21 ,your solution is right what the OP needs.
    The code below could be used if someone wants the maximum of all the above rows.
    Please Login or Register  to view this content.
    Last edited by p24leclerc; 01-22-2014 at 08:26 AM.

  10. #10
    Registered User
    Join Date
    01-15-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: If partial string = "dup" is in Column A, insert a row below that cell.

    Thanks everyone for the help. Seems the code works. What is the best way to learn the basic definitions of the language used in VBA? Is there a public dictionary that defines all these "commands"?

+ 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. VBA to insert pictures to " insert comment " or "Text box" in cell E5 and E15
    By Rocky2013 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-20-2013, 08:10 PM
  2. [SOLVED] If there is any text in column "A$" on "sheet1" then move cell to column "A$" on "sheet2"
    By ckgeary in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-27-2013, 08:28 PM
  3. SUMPRODUCT with "*" partial string lookup
    By timjames in forum Excel General
    Replies: 8
    Last Post: 09-02-2011, 08:54 AM
  4. Increment Cell Count If Column Contains "String"
    By Barrelroll in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2010, 11:45 PM
  5. Disabling "Entire &row/&column" in Delete/Insert Cell
    By Gap in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2005, 12:06 PM

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