Avatar of sandramac
sandramac
 asked on

Paste Coding

Hello all, I got this solution from an earlier question, listed below,  trying to figure out how I would add another criteria, in the copy data line, I need it instead of pasting into A3, paste into the cell two rows below the cell that has "DTE 2" in column A.  Thanks.

Public Sub Workbook_Open()
Dim ws As Worksheet
Dim result As Range
Application.DisplayAlerts = False

    '-- open other excel file
    Set ws = Workbooks.Open("\\data\mas.xlsx").Sheets("TAC MET")
       
    '-- search for CAO
    Set result = ws.UsedRange.Find("CAO")
    If result Is Nothing Then MsgBox ("CAO could not be found"): End
   
    '-- copy data
    ws.Range("A3:G" & result.Row - 1).Copy ThisWorkbook.Sheets("TAC MET").Range("A3")

    '-- close other excel file
    Set result = Nothing
    ws.Parent.Close
    Set ws = Nothing
   
  End Sub
Microsoft Excel

Avatar of undefined
Last Comment
TommySzalapski

8/22/2022 - Mon
TommySzalapski

To match the current code, you could do something like
    Set dst = ThisWorkbook.Sheets("TAC MET").UsedRange.Find("DTE 2")
    If dst Is Nothing Then MsgBox ("DTE 2 could not be found"): End

Then change the copy line to
    ws.Range("A3:G" & result.Row - 1).Copy dst.Offset(0,3)
ASKER CERTIFIED SOLUTION
TommySzalapski

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy