Results 1 to 40 of 45

Thread: [RESOLVED] Copy From One WorkBook To Another: Excel VBA

Threaded View

  1. #37
    New Member
    Join Date
    Jul 2011
    Posts
    14

    Re: [RESOLVED] Copy From One WorkBook To Another: Excel VBA

    Ok this is the code to make it loop and search for the correct column name
    vb Code:
    1. Sub Copy()
    2.      
    3.     Dim i As Integer, x As Long, z As Long
    4.     Dim Source As Workbook
    5.     Dim LastRow As Long
    6.     Dim OriginalWorkBook As Workbook
    7.     Set OriginalWorkBook = ThisWorkbook
    8.    
    9.     Const MyDir As String = "C:\Users\Shadow\Desktop\file a&b\"
    10.     Set Source = Workbooks.Open(MyDir & "file b.xlsx")
    11.    
    12.    
    13.     Application.ScreenUpdating = False
    14.     For x = 1 To 5
    15.      Source.Sheets("Tabelle1").Activate
    16.       For z = 1 To 5
    17.    If OriginalWorkBook.Worksheets("Tabelle1").Cells(1, x) = Source.Worksheets("Tabelle1").Cells(1, z) Then
    18.    
    19.     LastRow = Source.Worksheets("Tabelle1").Cells(Rows.Count, z).End(xlUp).Row
    20.  
    21.     Source.Worksheets("Tabelle1").Range(Cells(2, z), Cells(LastRow, z)).Select
    22.     Selection.Copy
    23.     OriginalWorkBook.Activate
    24.     i = OriginalWorkBook.Worksheets("Tabelle1").Cells(Rows.Count, x).End(xlUp).Row
    25. OriginalWorkBook.Worksheets("Tabelle1").Cells(i + 1, x).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:= _
    26.         False, Transpose:=False
    27.    End If
    28.    Next z
    29.    z = 0
    30. Next x
    31.        
    32. Application.ScreenUpdating = True
    33.      End Sub
    Hope this helps and does what you need.... and like you said, if someone else wants to help. go ahead.
    Attached Files Attached Files
    Last edited by Hack; Aug 17th, 2011 at 07:56 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width