Page 2 of 2 FirstFirst 12
Results 41 to 45 of 45

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

  1. #41
    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.

  2. #42
    New Member
    Join Date
    Jul 2011
    Posts
    14

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

    you have to change the

    Const MyDir As String = "C:\Users\Shadow\Desktop\file a&b\"

    to the correct address in your computer

  3. #43
    New Member
    Join Date
    Sep 2011
    Posts
    1

    Re: Copy From One WorkBook To Another: Excel VBA

    Dim wbk As Workbook
    strSecondFile = "D:\Excel\BOE.xls"
    Set wbk = Workbooks.Open(strSecondFile)


    in the 3rd line i received an error.Error is Subscript out of range.But the excel file present in the same location.If u know answer reply me soon.

  4. #44
    New Member
    Join Date
    Jul 2011
    Posts
    14

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

    I'm testing it and it seems to work fine.... verify the extension on the file and the actual address. that error is given when the file can't be found.... try closing the file when running the script... it may help

  5. #45
    Junior Member
    Join Date
    Sep 2011
    Posts
    23

    Re:Copy From One WorkBook To Another: Excel VBA

    Dear All

    I have been searching for a VBA solution to my problem. On reading the Posts here, I realised they relate almost to what I need. I should be very grateful to forum members for help, please.

    I have the following two sheets in Excel:

    a) Sheet 1 named (Receipts) with 2 columns as follows:

    Column A = Invoice No.
    Column B = Date Paid (current receipts)


    b) Sheet 2 named (DataTable) with about 8 columns, which include the following:

    Column A = Invoice No.
    Column G = Date Paid


    The invoice numbers in Sheet 1 column A are also available in Sheet 2 column A.

    Column G in Sheet 2 contains both the actual dates invoices were paid (in dd/mm/yyyy format) and also the text ‘UNPAID’ for those invoices not yet paid.

    I need help with a VBA code that will replace the texts ‘UNPAID’ in whichever cells they appear in Sheet 2 Column G, with the actual dates paid, as shown in Sheet 1 Column B, in respect of all the invoice numbers listed also in Sheet 1 Column A.

    IN SUMMARY:
    a) Go to Sheet 1 (named ‘Receipts’)
    b) Pick the invoice nos. in Column A including their related ‘dates paid’ in Column B.
    c) Go to Sheet 2 (named ‘Data Table’)
    d) Search Column A for the invoice nos. picked from Sheet 1 (named ‘Receipts’)
    e) For each matching invoice no. found in Sheet 2 (Data Table), replace the text ‘UNPAID’ which appears against that invoice no. in Column G with the ‘date paid’ value picked up from Sheet 1.
    f) All invoice nos. from Sheet 1 Column A that already have ‘date paid’ values in Sheet 2 Column G against their corresponding nos. should be ignored, (i.e. no action).

    I have attached a small sample of the sheets referred to. I need help with this as the entries I am regularly dealing with run into hundreds of rows. The Data Table (Sheet 2) is regularly updated with new unpaid invoices. At the same time, Sheet 1 (Receipts) is also updated with very many paid invoices nos. and dates added regularly.

    Thanks all in advance.

    Kenny

Page 2 of 2 FirstFirst 12

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