Copy Data from Closed File to Existing File

Joined
May 18, 2012
Messages
1
Reaction score
0
Hi All,

I have created a macro for following functions.

1. Open the Workbook
2. Copy data (from C12 : D12 to Active cells)
3. Paste the data in already opend sheet. Paste from the next empty cells.

When am using the macro in Module, It is Working, however when i have assigned the Button, it is not working and showing at

Code:
Range("C12:D" & DLsummary).Select

Error message " Run Time Error '1004' Select method of Range Class Faild (Value of "1048576")

Complete Code is below:

Code:
Private Sub CommandButton1_Click() 
    Dim strcheminFichier As String 
    Dim Name_File As String 
    Dim LoadFile As Variant 
    Dim Workbook_Name As String 
    Dim x 
    Dim Y 
    Workbook_Name = ThisWorkbook.Name 
    strcheminFichier = Application.GetOpenFilename("xls File (*.xls), *.xls", , "Select PPV Oracle report", , False) 
    If strcheminFichier = "False" Then 
        MsgBox "Please select file" 
        Exit Sub 
    End If 
    LoadFile = Split(strcheminFichier, "\") 
    Name_File = LoadFile(UBound(LoadFile)) 
    Workbooks.Open Filename:=strcheminFichier 
     
    Windows(Name_File).Activate 
    DLsummary = Range("A12").End(xlDown).Row 
    Sheets("Summary").Select 
    Range("C12:D" & DLsummary).Select 
    Selection.Copy 
     
    Windows(Workbook_Name).Activate 
    Sheets("Rates").Select 
    nbLigne = Range("A65536").End(xlUp).Row 
    Range("B" & nbLigne + 1).Select 
    ActiveSheet.Paste 
     
    Windows(Workbook_Name).Activate 
    Windows(Name_File).Activate 
    ActiveWindow.Close 
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top