Results 1 to 25 of 25

Conditional Copy Data from One sheet to another workbook

Threaded View

  1. #1
    Forum Contributor
    Join Date
    08-10-2016
    Location
    Pakistan
    MS-Off Ver
    365
    Posts
    242

    Conditional Copy Data from One sheet to another workbook

    I need to copy data from one sheet to another by following these conditions:
    1) User should select/browse for a file, from the opened file, it copies data from column A to Column D from sheet1
    2) Column A has unique numbers while column C & D has duplication, it should ignore duplicate.it copies only unique numbers in Column A and their respective data in column B, C & D
    3) It paste the Data in Dashboard file(main file) in sheet RawData at column AH to AK by looking into last used row
    Image: as shown in image, it should copy the highlighted data and ignore duplication

    I have written below code but it,s not according to my requirement, please help me
    Private Sub copy()
    Dim wsCopy As Worksheet
    Dim wsDest As Worksheet
    Dim lCopyLastRow As Long
    Dim lDestLastRow As Long
    Dim FileToOpen As Variant
    Dim OpenBook As Workbook
    
    Application.ScreenUpdating = False
    
    FileToOpen = Application.GetOpenFilename(Title:="Browse for Berkhund File & Import", 
    FileFilter:="Excel Files (*.xls*),*xls*")
    If FileToOpen <> False Then
    Set OpenBook = Application.Workbooks.Open(FileToOpen)
    
    'Set variables for copy and destination sheets
    Set wsCopy = OpenBook.Sheets(1)
    Set wsDest = ThisWorkbook.Worksheets(1)
    
    '1. Find last used row in the copy range based on data in column A
     lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row
    
    '2. Find first blank row in the destination range based on data in column AH
     'Offset property moves down 1 row
     lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "AH").End(xlUp).Offset(1).Row
    
    '3. Copy & Paste Data
    wsCopy.Range("A2:D" & lCopyLastRow).copy _
    wsDest.Range("AH" & lDestLastRow)
    OpenBook.Close False
    'Optional - Select the destination sheet
    wsDest.Activate
    
    'End Sub
    End If
    Application.ScreenUpdating = True
    
    Sheets("RawData").Activate
    
    End Sub
    sample.PNG
    Attached Files Attached Files
    Last edited by Zahid0111; 03-15-2020 at 12:40 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA: Copy Conditional Formatting from one sheet to another in the same workbook
    By devildogdad76 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-25-2019, 01:47 AM
  2. Copy Conditional Formatting from one sheet to another in the same workbook
    By devildogdad76 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-24-2019, 05:06 AM
  3. [SOLVED] Copy data from multiple WorkBook structures to the same sheet on another workbook
    By tax112 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-16-2018, 09:43 AM
  4. Copy data from one workbook to a specific sheet in another workbook without overriding
    By cdhampshire in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2017, 01:06 PM
  5. Replies: 6
    Last Post: 04-10-2013, 11:02 PM
  6. Conditional copy of a column in one sheet to another workbook transposed
    By gherzberg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-30-2012, 08:49 AM
  7. Replies: 0
    Last Post: 08-11-2011, 01:23 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