Results 1 to 16 of 16

Change VBA to insert copied rows not paste them.

Threaded View

  1. #1
    Registered User
    Join Date
    10-01-2014
    Location
    Tx
    MS-Off Ver
    2013
    Posts
    50

    Change VBA to insert copied rows not paste them.

    Hello! I am new to VBA as you will probably be able to tell. I have read a lot on this forum and I am having a great time learning!

    My problem:

    I need to copy rows of data from the master sheet(sheet4) and insert into other sheets depending on the data in column A. The below code does everything correctly except it paste the rows instead of inserting them which overwrites my subtotaling data at the bottom. If it helps I can insert/paste the copied rows into row 8 in all other sheets as they are all the exact same with exception to the master sheet.

    OR...would I be better off making my tech sheets section for pasting longer than then i expected the pasted data to be and have a code to delete unused rows?

    I really hope this is understandable as I am horrible at explaining things. lol

    The code I was trying:
    Sub Master_to_tech()
         
       '872006
        Dim lastrow As Long, lastcol As Long, nextrow As Long
        Dim rng As Range
         
        Application.ScreenUpdating = False
         
        nextrow = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row + 1
         
        With Sheet4
            lastrow = .Cells(Rows.Count, "F").End(xlUp).Row
            lastcol = .Cells(1, Columns.Count).End(xlToLeft).Column
            .AutoFilterMode = False
            Set rng = .Range("A1", .Cells(lastrow, lastcol))
            rng.AutoFilter field:=1, Criteria1:="DVOK872006"
            rng.Offset(1, 0).SpecialCells(12).Copy Sheet2.Range("A" & nextrow)
            rng.Offset(1, 0).EntireRow.Delete Shift:=xlUp
            .AutoFilterMode = False
        End With
         
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
         
        Set rng = Nothing
         
        '872008
        Application.ScreenUpdating = False
         
        nextrow = Sheet3.Cells(Rows.Count, "A").End(xlUp).Row + 1
         
        With Sheet4
            lastrow = .Cells(Rows.Count, "F").End(xlUp).Row
            lastcol = .Cells(1, Columns.Count).End(xlToLeft).Column
            .AutoFilterMode = False
            Set rng = .Range("A1", .Cells(lastrow, lastcol))
            rng.AutoFilter field:=1, Criteria1:="DVOK872008"
            rng.Offset(1, 0).SpecialCells(12).Copy Sheet3.Range("A" & nextrow)
            rng.Offset(1, 0).EntireRow.Delete Shift:=xlUp
            .AutoFilterMode = False
        End With
    End Sub
    I have attached a very short version of my workbook(as in the end it will have over 40 sheets) and what I need the end result to be. Thanks so much in advance!
    after code.xlsmbefore code.xlsm
    Last edited by baby_kay_2003; 10-01-2014 at 01:47 PM. Reason: code tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Change in code to get it to insert two blank rows instead of one and paste text
    By Excelsemi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-23-2014, 12:11 PM
  2. Replies: 0
    Last Post: 03-15-2013, 08:16 AM
  3. Copy paste data, insert rows, insert data and change . to -
    By xWiZardx in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2010, 01:44 AM
  4. Insert Copied Rows
    By Altec101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-23-2007, 06:49 AM
  5. Can't Insert Copied Rows
    By Kent in forum Excel General
    Replies: 0
    Last Post: 04-07-2005, 06:54 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