+ Reply to Thread
Results 1 to 4 of 4

Copy data from file to existing file to corresponding row and Column

Hybrid View

  1. #1
    Forum Contributor G.Bregvadze's Avatar
    Join Date
    12-06-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2010 - 2016
    Posts
    256

    Copy data from file to existing file to corresponding row and Column

    Working on project where one component of calculations requires:

    1. When clicking some button to offer dialog windows asking which file to open
    2. After choosing file: open the file
    3. Copy data from Predefined sheet (in this case Summary sheet) from area with data (from Grey Cells (here starting point is always same Cell- E5, but the last raw and column should be found using may be raw count and column count?)
    4. Paste in opened workbook (in the Summary sheet) in Grey area (based on column and raw values


    The case is that the columns might be added, items also might be changed current file vs old, therefore the direct copy paste will not work and the copy of grey area should be match with column and raw values.


    attaching the sample file for Copying the data and for pasting the data.
    Attached Files Attached Files
    Last edited by G.Bregvadze; 08-03-2020 at 09:43 AM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,901

    Re: Copy data from file to existing file to corresponding row and Column

    Place this macro in the "Copying" file.
    Sub CopyData()
        Application.ScreenUpdating = False
        Dim flder As FileDialog, FileName As String, FileChosen As Integer, wkbSource As Workbook, wsSource As Worksheet, wsDest As Worksheet
        Dim LastRow As Long, lCol As Long, x As Long, itm As Range, store As String, fnd As Range, Val As String, i As Long, v1
        x = 4
        Set wsSource = ThisWorkbook.Sheets("Summary")
        LastRow = wsSource.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        lCol = wsSource.Cells(3, Columns.Count).End(xlToLeft).Column
        v1 = wsSource.Range("B3", wsSource.Range("B" & Rows.Count).End(xlUp)).Resize(, lCol - 1).Value
        Set flder = Application.FileDialog(msoFileDialogFilePicker)
        flder.Title = "Please Select a file."
        FileChosen = flder.Show
        FileName = flder.SelectedItems(1)
        Set wkbSource = Workbooks.Open(FileName)
        Set wsDest = Sheets("Summary")
        For i = 3 To UBound(v1, 1)
            Val = v1(i, 1)
            Set itm = wsDest.Range("B:B").Find(Val, LookIn:=xlValues, lookat:=xlWhole)
            If Not itm Is Nothing Then
                For x = 4 To lCol - 1
                    store = v1(1, x)
                    Set fnd = wsDest.Rows(3).Find(store, LookIn:=xlValues, lookat:=xlWhole)
                    If Not fnd Is Nothing Then
                        With wsDest
                            .Cells(itm.Row, fnd.Column) = wsSource.Cells(i + 2, x + 1)
                        End With
                    End If
                Next x
            End If
        Next i
        Application.ScreenUpdating = True
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Contributor G.Bregvadze's Avatar
    Join Date
    12-06-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2010 - 2016
    Posts
    256

    Re: Copy data from file to existing file to corresponding row and Column

    Hi,
    Thank you very much, this is working perfectly.

    Appreciate your support.

    Thank you very much

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,901

    Re: Copy data from file to existing file to corresponding row and Column

    You are very welcome.

+ 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 a file from one folder to another and replace the existing file
    By KColgrove in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2019, 08:21 PM
  2. Require help in modifying the code to copy data to an existing file instead of new file
    By ahamedcader in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-13-2014, 02:57 PM
  3. macro to open, copy paste from existing excel file to a new blank file
    By 2blessed in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2012, 06:05 PM
  4. Copy Data from Closed File to Existing File
    By srikanthbenoni in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-21-2012, 08:36 AM
  5. Macro to copy data from csv file base on cells in existing workbook
    By wallstudio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-30-2011, 03:29 AM
  6. Macro to copy a column data to flat file or text file
    By vinaynagasani in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-01-2009, 10:56 AM
  7. Open New File & Copy To Existing File
    By Pedros in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2007, 03:16 AM

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