Consulting

Results 1 to 2 of 2

Thread: Import Second Excel file

  1. #1

    Import Second Excel file

    Hi,

    Open *.xls and move data to REPORT spread sheet, now I want to import second *.xls file, once the first import is finished. Only 2 xls to Import. Some one help to modify this.

    Public Sub OpenFile()
        Dim FileToOpen As String
        Dim CurDir As String
        FileToOpen = Application.GetOpenFilename
        Workbooks.Open Filename:=FileToOpen
    
    
    Call MoveData
    End Sub
    
    
    Public Sub MoveData()
    Application.ScreenUpdating = False
        Dim wb1 As Workbook, wb2 As Workbook
        Dim ws1 As Worksheet, ws2 As Worksheet
        Dim LastRow As Long, NextRow As Long
        Set wb1 = ThisWorkbook
        Set wb2 = ActiveWorkbook
        Set ws1 = wb1.Sheets("REPORT")
        Set ws2 = wb2.Worksheets(1)
        LastRow = ws2.Cells(Rows.Count, 1).End(xlUp).row
        NextRow = ws1.Cells(Rows.Count, 1).End(xlUp).row + 1
    
    
        For i = 3 To LastRow
            ws1.Cells(NextRow, 1) = CDate(ws2.Cells(i, 5))
            ws1.Cells(NextRow, 1).NumberFormat = "dd/mm/yyyy"
            ws1.Cells(NextRow, 2) = ws2.Cells(i, 8)
            ws1.Cells(NextRow, 3) = ws2.Cells(i, 17)
            ws1.Cells(NextRow, 3).NumberFormat = "0.00"
                    
            NextRow = NextRow + 1
        Next i
        wb2.Close SaveChanges = False
        ws1.Activate
        Set wb1 = Nothing
        Set wb2 = Nothing
        Set ws1 = Nothing
        Set ws2 = Nothing
        
    End Sub

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    If you are able to write such extensive code for such a simple task, you should be able to adapt it.
    You should reduce it to 3 code lines.

Posting Permissions

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