Link to home
Start Free TrialLog in
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
Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

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
Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial