Consulting

Results 1 to 2 of 2

Thread: auto transfer multiple rows from one excel to another

  1. #1
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    1
    Location

    auto transfer multiple rows from one excel to another

    need to auto transfer specific multiple rows from one excel to another excel file into specific rows of the same fields

    attached two files plz transfer blank colums automaticaly from other file using button option
    Attached Files Attached Files

  2. #2
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello sai0449,

    Will you always have the same number of rows filled with data in each workbook's table?

    Will both tables have the same column headers?

    If the answer to both questions above is yes then this macro should work for you. This macro assumes only 2 workbooks will open. The macro enabled workbook and an XLSX workbook which will receive the data. If your files are protected then macro will need to be modified to remove and restore worksheet protection or it will not run.

    The name of the source and destination worksheets are set to "Sheet1". Change these if you need to. A button has been add to the source worksheet to run the macro.

    Sub CopyData()
    
        Dim ColArray    As Variant
        Dim DstRng      As Range
        Dim DstWkb      As Workbook
        Dim DstWks      As Worksheet
        Dim n           As Long
        Dim SrcRng      As Range
        Dim SrcWkb      As Workbook
        Dim SrcWks      As Worksheet
        
            For n = 1 To 2
                Select Case Workbooks(n).Name
                    Case Is = ThisWorkbook.Name
                        Set SrcWkb = Workbooks(n)
                        Set SrcWks = SrcWkb.Worksheets("Sheet1")
                        Set SrcRng = SrcWks.Range("A1").CurrentRegion
                    Case Else
                        Set DstWkb = Workbooks(n)
                        Set DstWks = DstWkb.Worksheets("Sheet1")
                        Set DstRng = DstWks.Range("A1").CurrentRegion
                End Select
            Next n
            
            ColArray = Array(3, 4, 5, 7, 10, 11, 12, 13, 14, 15, 16, 17, 20)
            
            For n = 0 To UBound(ColArray)
                DstRng.Columns(ColArray(n)).Value = SrcRng.Columns(ColArray(n)).Value
            Next n
                
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •