get specific cell values from several workbooks and place in new workbook sheet

excel 2010

I need a routine that will:
Look at any workbook in a folder..

Open each workbook:
Get the file name of the workbook.

 and look for 3 worksheets.

From: CompanyData
Gets cell value from :
D3, D10, F22, R23

From: CorporateData
Gets cell value from :
B4, D11, G21, S12, D34

From: DSNData
Gets cell value from :
B2, W12, G21, S12, F45

Put all this data into its each row with the name of the worksheet first
           A             B       C       D       E       etc...
<filename>     D3     D10  F22   R23    etc,....

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi, fordraiders.

Please see attached. In line three, you will need to change the directory details (don't forget the trailing back-slash!), The code is
Option Explicit

Const xDIR = "D:\Process_Files\" ' Trailing "\" needed.

Sub Process_Files()
Dim xCount    As Long
Dim xFile     As String
Dim xOutput   As Worksheet
Dim xBook     As Workbook

Set xOutput = Sheets.Add
xOutput.Name = Format(Now(), "YYYY-MM-DD_HH-NN-SS")
Range("A1:O1") = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O")
xCount = 1

xFile = Dir(xDIR & "*.xls*")
Do While xFile <> ""

    Debug.Print xFile
    Set xBook = Workbooks.Open(xDIR & xFile)

    xCount = xCount + 1

    xOutput.Cells(xCount, 1) = xFile
    If Sheet_Exists("CompanyData") Then xOutput.Range("B" & xCount & ":E" & xCount) _
        = Array(Sheets("CompanyData").Range("D3") _
        , Sheets("CompanyData").Range("D10") _
        , Sheets("CompanyData").Range("F22") _
        , Sheets("CompanyData").Range("R23"))
    If Sheet_Exists("CorporateData") Then xOutput.Range("F" & xCount & ":J" & xCount) _
        = Array(Sheets("CorporateData").Range("B4") _
        , Sheets("CorporateData").Range("D11") _
        , Sheets("CorporateData").Range("G21") _
        , Sheets("CorporateData").Range("S12") _
        , Sheets("CorporateData").Range("D34"))
    If Sheet_Exists("DSNData") Then xOutput.Range("K" & xCount & ":O" & xCount) _
        = Array(Sheets("DSNData").Range("B2") _
        , Sheets("DSNData").Range("W12") _
        , Sheets("DSNData").Range("G21") _
        , Sheets("DSNData").Range("S12") _
        , Sheets("DSNData").Range("F45"))
    xBook.Close savechanges:=False
    xFile = Dir

MsgBox ("Run complete. " & xCount - 1 & " files processed.")

End Sub

Function Sheet_Exists(xSheet_Name As String, Optional xBook As String) As Boolean

If xBook = "" Then xBook = ActiveWorkbook.Name

Sheet_Exists = False

On Error Resume Next
    Sheet_Exists = (Workbooks(xBook).Sheets(xSheet_Name).Name = xSheet_Name)
On Error Resume Next

End Function

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FordraidersAuthor Commented:
Thanks so much...!..

This will just copy the data value ...right?...and not any formulas that may be in those cells ?
Thanks, fordraiders.

Yes, just the values.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.