Closed Thread
Results 1 to 7 of 7

Change in code to get it to insert two blank rows instead of one and paste text

  1. #1
    Registered User
    Join Date
    03-06-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    83

    Change in code to get it to insert two blank rows instead of one and paste text

    Hello

    I have this code for searching a column when a number changes and insert rows above and below when there is a change.

    Please Login or Register  to view this content.
    So fx. Column C:
    1
    1
    1
    2
    2

    Have to be:

    new row = "Text"
    1
    1
    1
    new row "Text 2"
    new row "text"
    2
    2
    new row "text 2"
    new row "Text"

    So when a new value begins: "Text"
    When it ends, "text 2"
    When the new value begins, same "text"
    when it ends, same "text 2

    Appreciate any help.
    Kind regards
    Last edited by arlu1201; 05-23-2014 at 12:10 PM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,936

    Re: Change in code to get it to insert two blank rows instead of one and paste text

    I have assumed that column C has a header in cell C1, and that there are no blanks.

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    03-06-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    83

    Re: Change in code to get it to insert two blank rows instead of one and paste text

    Thanks for the reply!

    There shouldn't be any blank cells, and yes there is a header in Row 1.
    However, I have the extracted the information I need to further dismantle from a bigger sheet with the following forumlas:
    =IFERROR(SMALL(IF(ISNUMBER(MATCH(Sheet1!$A$2:$A$499;Sheet1!$B$2:$B$499;0));ROW(Sheet1!$A$2:$A$499)-ROW(Sheet1!$A$2)+1);ROWS($A$2:A2));"") In Column A, and then dragged it down.
    In the rest of the columns from B to I I have dragged down the following: =IF($A2="";"";INDEX(Sheet1!$A$2:$E$499;$A2;MATCH(B$1;Sheet1!$A$1:$E$1;0)))

    So when I insert a new row it apparently just replaces the one with the formula in, is there anyway to fix this - ?

    I've changed the ranges from your code to my workbook:
    Please Login or Register  to view this content.
    Last edited by arlu1201; 05-23-2014 at 12:10 PM.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,936

    Re: Change in code to get it to insert two blank rows instead of one and paste text

    How about: the code copies values from the current sheet to a new blank sheet and then processes that, or just converts the formulas to values - or just use the values from the bigger sheet? Are the numbers going to change after you run this code, so that you still need formulas?

    You could also look at the Filtering and Subtotaling functionality (Data / Outline) and use that on the bigger sheet - no formulas, no extraction.....

  5. #5
    Registered User
    Join Date
    03-06-2014
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    83

    Re: Change in code to get it to insert two blank rows instead of one and paste text

    hmm, yea okay.. I could perhaps consider that.

    No the numbers are not gonna change, they are the same all the way through this, so I wouldn't need the formulas no..only the information set up in the right way because I have to put it in a specific system.
    It was a way to match cells in two different columns and copy the information from only the first column with the same value, and then take all the info from the rest of the columns without copying the matching value in column b and putting that in a new sheet.
    But the whole excercise is a bit complex to me - that's why I've tried to do it this way, but for sure there is a smarter way.
    The basic thing is that I have several columns and rows, the first two columns consists of some of the same numbers, whenever there is a number in Column A that matches a number in B, I need to copy the information from that column B and the specifc row into a new row with the text "Begin-total" and also a row below with text "end-total"

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,936

    Re: Change in code to get it to insert two blank rows instead of one and paste text

    Try this version

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Change in code to get it to insert two blank rows instead of one and paste text

    Excelsemi,

    2 pointers -

    1. I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. In order to put code tags, either type [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] at the end of it, OR you can highlight your code and click the # icon at the top of your post window.

    2. This thread has been posted in the Commercial services subforum, hence will be closed.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Changing code from deleting rows to cut/paste rows into another sheet and delete blank row
    By kmarshall6576 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-18-2013, 01:54 AM
  2. Replies: 1
    Last Post: 02-09-2012, 09:19 PM
  3. Insert Blank rows after every date change
    By josigrozi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-15-2011, 07:23 AM
  4. Insert 2 blank rows and sum columns based on cell value change
    By parreola in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2009, 11:14 PM
  5. Find blank rows and insert text
    By bpreas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-09-2007, 10:43 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