+ Reply to Thread
Results 1 to 4 of 4

insert rows + copy rows except certain columns

Hybrid View

  1. #1
    Registered User
    Join Date
    03-26-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2010
    Posts
    18

    insert rows + copy rows except certain columns

    Hi guys,

    I need your help for the following problem, hope not too difficult

    Presentation:
    I attached the sample where we have Sheet1 and Sheet2.
    In sheet1 I have a lot of rows and columns, with many formulas almost in each cell. In Sheet2 I have again formulas and so on. Important: the no of rows in Sheet 2 can vary each time I’m running the macro.

    The Problem:
    I have to insert rows below the active row from Sheet1 and copy/paste this row into the new inserted ones, except columns E and F which must be copied from Sheet2. The no of rows inserted is given by the no of rows from Sheet2 (except header).

    Thank you all !
    Attached Files Attached Files
    Last edited by costin; 07-06-2013 at 10:45 AM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: insert rows + copy rows except certain columns

    Sub Insert_Data_Rows()
        Dim RowCount As Long, r As Long
        RowCount = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row - 1
        r = ActiveCell.Row
        Application.ScreenUpdating = False
        Range("A" & r & ":F" & r).Copy
        r = r + 1
        Range("A" & r & ":F" & r).Resize(RowCount).Insert Shift:=xlShiftDown
        Range("E" & r & ":F" & r).Resize(RowCount).Value = _
            Sheets("Sheet2").Range("C2:D2").Resize(RowCount).Value
        Application.CutCopyMode = True
        Application.ScreenUpdating = True
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    03-26-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: insert rows + copy rows except certain columns

    What a masterpiece! Works exactly as I wanted! Many many thanks. I have to visit Florida and give you a beer

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: insert rows + copy rows except certain columns

    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)

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