VB in Excel

Discussion in 'Web Development and Programming' started by dhoppas, Sep 2, 2011.

  1. dhoppas

    dhoppas Regular Member

    Joined:
    Jan 7, 2011
    Messages:
    1
    Likes Received:
    0
    I just put this code together at work to grab specific information from 1,181 old excel sheets and place them in one centeralized document!

    I'm sure there are better, and possibly easier ways to do this, but it's my first VB code in forever, and it works, so I'm ok with it!

    Code:
    Sub FillSheetFromFiles()
        Dim fileArray As Variant
        Dim xlTmp As Excel.Application
        Dim fileTmp As Variant
        Dim cellTmp As Variant
     
        Set xlTmp = New Excel.Application
        fileArray = Worksheets("Sheet1").Range("a1:a1181").Value
    
        Sheets("Sheet2").Select
    
        'Looping structure to look at array.
        For i = 1 To UBound(fileArray)
            fileTmp = fileArray(i, 1)
            xlTmp.Workbooks.Open fileTmp
            cellTemp = "A" & (i + 1)
            ActiveSheet.Range(cellTemp).Select
            ActiveCell.Value = xlTmp.Range("C10")
            ActiveCell.Offset(0, 1).Value = xlTmp.Range("C12")
            ActiveCell.Offset(0, 2).Value = xlTmp.Range("C13")
            ActiveCell.Offset(0, 3).Value = xlTmp.Range("C9")
            xlTmp.ActiveWorkbook.Close False
            xlTmp.Workbooks.Close
        Next
    End Sub
    My coworker's don't want me to leave when I graduate in December! LOL
     
  2. Awesomesauce

    Awesomesauce Regular Member

    Joined:
    Nov 24, 2010
    Messages:
    31
    Likes Received:
    0
    Location:
    Topeka, KS

    Attached Files:

Similar Threads
Loading...

Share This Page