+ Reply to Thread
Results 1 to 2 of 2

Conditional Copy & Paste

  1. #1
    Forum Contributor
    Join Date
    07-16-2009
    Location
    NA
    MS-Off Ver
    MS Excel 2010
    Posts
    237

    Conditional Copy & Paste

    Hello Guys,

    I am looking for a macro that will conditionally copy & paste the data
    I have a file macro.xlsm & vba macro will be placed in a macro.xlsm & i have one more file sample1.xls (both files are located in different path & the path should be hardcoded in the macro, so that i can change it as per my needs )
    We have to copy data from sample1.xls (sheet1 ) & paste it to macro.xlsm (sheet2)

    Condition: Macro.xlsm (sheet2) may be a blank sheeet or it may have a data, If it is a blank sheet then simply copy paste the complete data from sample1.xls (sheet1 ) to macro.xlsm (sheet2) & if It has a data then match column B data of macro.xlsm(sheet2) with column B of sample1.xls (sheet1) & if it matches then dont copy that row & copy rest of data & paste it

    Plz see Output sheet(If macro.xlsm has data in sheet2 then that will be the output& if it is a blank sheet then simple copy & paste)



    Thnx
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this demonstration !


    According to your attachment as a VBA beginner starter to paste to the Sheet2 worksheet module :

    PHP Code: 
    Sub Demo1()
            
    F$ = ThisWorkbook.Path "\Sample1.xls":  If Dir(F) = "" Then Beep: Exit Sub
            L
    & = Me.UsedRange.Rows.Count + (Me.UsedRange.CountLarge 1)
            
    Application.ScreenUpdating False
        With Workbooks
    .Open(F).Sheets(1).UsedRange.Rows
            
    If L Then
                    V 
    Me.UsedRange.Columns(2).Value2
                    W 
    = .Columns(2).Value
                
    For R& = 2 To .Count
                    
    If IsError(Application.Match(W(R1), V0)) Then L 1: .Item(R).Copy Cells(L1)
                
    Next
            
    Else
                .
    Copy [A1]
            
    End If
                .
    Parent.Parent.Close False
        End With
            Application
    .ScreenUpdating True
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 08-09-2020 at 07:34 AM. Reason: optimization …

+ 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 & Paste VBA conditional
    By samarbac in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-29-2020, 11:54 AM
  2. Conditional Copy/Paste
    By EwaWieja in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-29-2015, 09:40 AM
  3. Conditional Copy & Paste
    By Victor Lim in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-09-2014, 03:29 AM
  4. Vba for conditional copy and paste
    By rikk1965 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2014, 03:37 AM
  5. Conditional Copy and Paste
    By FN2010 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-30-2012, 05:13 PM
  6. Conditional Copy paste
    By rlsublime in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-13-2012, 02:02 PM
  7. conditional copy/paste
    By Newbie904 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-02-2009, 04:04 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