+ Reply to Thread
Results 1 to 4 of 4

Match Value, Insert Rows, and Copy New Data Between Sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    01-25-2018
    Location
    USA
    MS-Off Ver
    2013
    Posts
    2

    Match Value, Insert Rows, and Copy New Data Between Sheets

    Very new to this. I am trying to automate updating a "master" sheet with new information from another sheet that is periodically updated (and still contains data from the sheet it will be going into). Sheet 6 has the new data and Sheet 4 is where it will need to go. Both sheets have a unique ID in column A. I need the macro to look at sheet 6 and find the first match between column A on sheet 6 and cell A3 on sheet 4, then copy all the rows from sheet 6 above the sheet 6 match and insert below the A3 on sheet 4 (below so the vlookups expand). It only needs to find the first match because they are both in descending order and the old sheet 6 data is already in sheet 4.

    Sheet 6 data starts in row 2 and sheet 4 data starts in row 3. I started with the macro below but it is probably garbage, I got it to insert the row but it will continue to go through Sheet4 which is pointless because it will just insert a new row every other row so it needs to stop after the first match. Thank you!

    Sub Insert()

    Dim Rng As Range
    Dim WorkRng As Range
    On Error Resume Next

    Set WorkRng = Range(Sheet6.Range("a3").End(xlDown))
    Set WorkRng = WorkRng.Columns(1)
    xLastRow = WorkRng.Rows.Count
    Application.ScreenUpdating = False
    For xRowIndex = xLastRow To 1 Step -1
    Set Rng = Sheet4.Range("A3" & xRowIndex)
    If Rng.Value = WorkRng.Value Then
    Rng.EntireRow.Insert Shift:=xlDown
    End If
    Next
    Application.ScreenUpdating = True


    End Sub

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,028

    Re: Match Value, Insert Rows, and Copy New Data Between Sheets

    Could you attach a copy of your file? It would make it easier to see how your data is organised and to test possible solutions.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    01-25-2018
    Location
    USA
    MS-Off Ver
    2013
    Posts
    2

    Re: Match Value, Insert Rows, and Copy New Data Between Sheets

    Thanks for responding. I cannot due to it being work related but if this helps think of it like

    Sheet 6:
    Column A
    5
    4
    3
    2
    1

    Sheet 4, Column A:
    3
    2
    1

    I need it to copy and insert the rows containing 4 and 5 from Sheet6 underneath the row containing 3 in Sheet4. Is this helpful?

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,028

    Re: Match Value, Insert Rows, and Copy New Data Between Sheets

    Try:
    Sub InsertRows()
        Application.ScreenUpdating = False
        Dim foundVal As Range
        Set foundVal = Sheets(6).Range("A:A").Find(Sheets(4).Range("A3").Value, LookIn:=xlValues, lookat:=xlWhole)
        If Not foundVal Is Nothing Then
            Sheets(6).Rows("2:" & foundVal.Row - 1).Copy
            Sheets(4).Rows(4).Insert
        End If
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
    End Sub

+ 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. Copy and paste rows from data onto sheets that match first column
    By sean.dolan93 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-20-2017, 03:40 PM
  2. insert rows and copy data across sheets - row quantity varies each time
    By Herbo76 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-01-2016, 10:48 AM
  3. Match two rows of different sheets and copy to new sheet
    By CalumRiley in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-07-2013, 12:05 PM
  4. Macro to insert rows in multiple sheets and copy formulas
    By syt0x in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-25-2013, 11:06 AM
  5. [SOLVED] Copy, paste and insert new rows into new sheets
    By nanas in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-10-2012, 10:35 PM
  6. 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
  7. Insert rows and copy data from other sheets
    By Popa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2008, 06:48 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