+ Reply to Thread
Results 1 to 6 of 6

VBA conditional copy and paste into another WB

  1. #1
    Forum Contributor
    Join Date
    01-25-2021
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    144

    VBA conditional copy and paste into another WB

    I'm trying to call a code from "VBA Code Runner - Excel Forum" wb......but it doesn't seem to be working.

    Note: I am very new to VBA so please provide a detailed explanation so I can adequately apply to my other wbs....thank you!


    In "Coaching Report - Dest - Excel Forum.xlsm" wb, "Mission Control" ws, cell "B3", there is a conditional value......in this case "Kendal Gholston".

    If in "Coaching Report - Copy - Excel Forum.xlsm" wb, "Full Append" ws, column "D" = "Kendal Gholston" (B3 of "Mission Control"), then I would like to copy those rows and paste/replace into "Coaching Report - Dest - Excel Forum.xlsm" wb, "Mission Control" ws, column "BI" (ignoring header).

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: VBA conditional copy and paste into another WB

    Hi JyothiGrace,

    Your problem looks like it needs a Power Query answer instead of VBA. You could use PQ and filter a File to only show the Names of "Kendal".

    On your specific problem it looks like you are looking for Kendal in the Supervisor column while it is really in the Name column. If you are close to writing the VBA to do your filter something like Name<>Supervisor is hard to find when your code is doing many other things.

    I hope this helps.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    01-25-2021
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    144

    Re: VBA conditional copy and paste into another WB

    I really need VBA rather than powerquery since the call runs about 150 destination workbooks. The time it takes for refresh is too long.......

    Yes.....I realize the column heading is incorrect.

  4. #4
    Forum Contributor
    Join Date
    01-25-2021
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    144

    Re: VBA conditional copy and paste into another WB

    I changed my code to just copy ALL data and replace in Dest Sheet but still getting "Application-defined or object-defined" error. Please see attached again to ID my error....

  5. #5
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: VBA conditional copy and paste into another WB

    Hello.
    I am assuming that the three workbooks are in the same folder.
    Test:

    PHP Code: 
    Sub Log_Copy_Paste()
    Dim ws2 As WorksheetmyPath$, myFile$, Tmp
    Dim Rng 
    As RangeTbl As ListObjectiKey$, piv As Range
    Application
    .ScreenUpdating False
    Rem 
    ----------------------------------------\
    myPath ThisWorkbook.PathmyFile "Coaching Report - Copy"
    Tmp Dir(myPath "\" & myFile & "*")
    If Tmp = "" Then MsgBox "
    Workbook" & myPath & "\" & myFile & "*" & vbLf & "not found.": End
    Rem ----------------------------------------\
    Set Rng = Workbooks.Open(myPath & "
    \" & Tmp, ReadOnly:=True).Sheets(1).Range("d1").ListObject.Range
    Rem ----------------------------------------\
    myPath = ThisWorkbook.Path: myFile = "
    Coaching Report Dest"
    Tmp = Dir(myPath & "
    \" & myFile & "*")
    If Tmp = "" Then MsgBox "
    Workbook" & myPath & "\" & myFile & "*" & vbLf & "not found.": End
    Rem ----------------------------------------\
    Set ws2 = Workbooks.Open(myPath & "
    \" & Tmp).Sheets(1)
    Set Tbl = ws2.Range("
    bk1").ListObject
    iKey = ws2.Range("
    b3")
    Rem ----------------------------------------\
    Set piv = Tbl.Range(1).Offset(1 + Tbl.ListRows.Count)
    piv(2) = "
    =" & Rng(2, 3).Address(0, 0, external:=True) & " """ & iKey & """"
    Rng.AdvancedFilter 2, piv.Resize(2), piv(3), False
    piv = "
    .": Tbl.Resize Tbl.Range.CurrentRegion
    piv.Resize(3, Tbl.ListColumns.Count).Delete xlShiftUp
    Rng.Worksheet.Parent.Close False
    End Sub 
    Attached Files Attached Files
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  6. #6
    Forum Contributor
    Join Date
    01-25-2021
    Location
    Atlanta, Georgia
    MS-Off Ver
    365
    Posts
    144

    Re: VBA conditional copy and paste into another WB

    I'm sorry beyond.Excel but I am unable to follow what you did. Can you just tell me what the error is in the attached coding?
    Attached Files Attached Files

+ 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. Conditional Copy & Paste
    By Zaeguzah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-09-2020, 06:53 AM
  2. Copy & Paste VBA conditional
    By samarbac in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-29-2020, 11:54 AM
  3. Conditional Copy/Paste
    By EwaWieja in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-29-2015, 09:40 AM
  4. conditional copy/paste
    By Newbie904 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-02-2009, 04:04 AM
  5. Conditional copy paste
    By sharpstyx in forum Excel General
    Replies: 1
    Last Post: 07-16-2009, 03:19 AM
  6. [SOLVED] Conditional Copy and paste
    By Pedro F. in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-24-2006, 11:55 AM

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