Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Multiple Excel File Import

I have multiple spreadsheets in the same folder. There are two variations of
these spreadsheets in this folder depending on the format required for that
client. I need the script to capture a couple cell locations from each of
these spreadsheets (cells depends on which format type) within the folder
path. Output would be into a new spreadsheet with file name and cell values
needed.

Hoping to save myself from opening each one and doing it manually. Any help
is appreciated!!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Multiple Excel File Import

On Dec 3, 6:01 am, M Scott wrote:
I have multiple spreadsheets in the same folder. There are two variations of
these spreadsheets in this folder depending on the format required for that
client. I need the script to capture a couple cell locations from each of
these spreadsheets (cells depends on which format type) within the folder
path. Output would be into a new spreadsheet with file name and cell values
needed.

Hoping to save myself from opening each one and doing it manually. Any help
is appreciated!!!


Check this out:

save this macro in a file called loopfolder.xls
Copy all xls files to one folder.
Fill in the variables in the following:

Sub FolderLoop()

Dim pathstr, strfile As String

Application.ScreenUpdating = False

pathstr = ""
strfile = ""


pathstr = "replace with the path of the folder with all the xls"
ChDir (pathstr)
strfile = Dir("*.xls")


Do While Len(strfile) 0
On Error GoTo errortrap


Workbooks.Open (pathstr & "\" & strfile)

x = Range("a1").Value ' change it to needed cell address
y = Range("a2").Value ' change it to needed cell address
Workbooks(strfile).Close

Application.Workbooks("LoopFolder.xls").Activate

Application.Selection.Value = x
Application.Selection.Offset(0, 1).Value = y
Application.ActiveCell.Offset(1, 0).Select




ChDir (pathstr)
strfile = Dir

errortrap:
Loop
Application.ScreenUpdating = True

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Multiple Excel File Import

Thanks. Got me something to start with!

" wrote:

On Dec 3, 6:01 am, M Scott wrote:
I have multiple spreadsheets in the same folder. There are two variations of
these spreadsheets in this folder depending on the format required for that
client. I need the script to capture a couple cell locations from each of
these spreadsheets (cells depends on which format type) within the folder
path. Output would be into a new spreadsheet with file name and cell values
needed.

Hoping to save myself from opening each one and doing it manually. Any help
is appreciated!!!


Check this out:

save this macro in a file called loopfolder.xls
Copy all xls files to one folder.
Fill in the variables in the following:

Sub FolderLoop()

Dim pathstr, strfile As String

Application.ScreenUpdating = False

pathstr = ""
strfile = ""


pathstr = "replace with the path of the folder with all the xls"
ChDir (pathstr)
strfile = Dir("*.xls")


Do While Len(strfile) 0
On Error GoTo errortrap


Workbooks.Open (pathstr & "\" & strfile)

x = Range("a1").Value ' change it to needed cell address
y = Range("a2").Value ' change it to needed cell address
Workbooks(strfile).Close

Application.Workbooks("LoopFolder.xls").Activate

Application.Selection.Value = x
Application.Selection.Offset(0, 1).Value = y
Application.ActiveCell.Offset(1, 0).Select




ChDir (pathstr)
strfile = Dir

errortrap:
Loop
Application.ScreenUpdating = True

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Multiple Excel File Import

After some tweaks, here's the final code. Thanks again dolswang!!!

Sub PrepareEOY()

Dim pathstr, strfile As String
Dim a, b, c, d, e As Integer

Application.ScreenUpdating = False

pathstr = ""
strfile = ""

pathstr = "Full directory path to folder"
ChDir (pathstr)
strfile = Dir("*.xls")

Range("A3").Select

Do While Len(strfile) 0

Workbooks.Open (pathstr & "\" & strfile)

If Range("'Sheet Name'!F10").Value = "RATE" Or Range("'Sheet
Name'!F10").Value = "Rate" Then ' To determine between two sheet types.
a = Range("'Sheet Name'!G38").Value ' change it to needed cell address
b = Range("'Sheet Name'!G39").Value ' change it to needed cell address
c = Range("'Sheet Name'!I38").Value ' change it to needed cell address
d = Range("'Sheet Name'!J38").Value ' change it to needed cell address
e = Range("'Sheet Name'!K38").Value ' change it to needed cell address
Else
a = Range("'Sheet Name'!G39").Value ' change it to needed cell address
b = Range("'Sheet Name'!G40").Value ' change it to needed cell address
c = Range("'Sheet Name'!I39").Value ' change it to needed cell address
d = Range("'Sheet Name'!J39").Value ' change it to needed cell address
e = Range("'Sheet Name'!K39").Value ' change it to needed cell address
End If

Workbooks(strfile).Close

Application.Selection.Offset(0, 1).Value = a
Application.Selection.Offset(0, 2).Value = b
Application.Selection.Offset(0, 3).Value = c
Application.Selection.Offset(0, 4).Value = d
Application.Selection.Offset(0, 5).Value = e
Application.Selection.Offset(0, 6).Value = strfile
Application.ActiveCell.Offset(1, 0).Select

ChDir (pathstr)
strfile = Dir

Loop

' AutoSum for total line
Application.Selection.Offset(0, 1).Select
AutoSum
Application.Selection.Offset(0, 1).Select
AutoSum
Application.Selection.Offset(0, 1).Select
AutoSum
Application.Selection.Offset(0, 1).Select
AutoSum
Application.Selection.Offset(0, 1).Select
AutoSum

Application.ActiveCell.Offset(1, 0).Select

Application.ScreenUpdating = True

End Sub

Sub AutoSum()

Dim cel1, cel2
ActiveCell.Offset(-1, 0).Select
cel1 = Selection.End(xlUp).Address
cel2 = ActiveCell.Address
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = "=sum(" & (cel1) & ":" & (cel2) & ")"

End Sub


"M Scott" wrote:

Thanks. Got me something to start with!

" wrote:

On Dec 3, 6:01 am, M Scott wrote:
I have multiple spreadsheets in the same folder. There are two variations of
these spreadsheets in this folder depending on the format required for that
client. I need the script to capture a couple cell locations from each of
these spreadsheets (cells depends on which format type) within the folder
path. Output would be into a new spreadsheet with file name and cell values
needed.

Hoping to save myself from opening each one and doing it manually. Any help
is appreciated!!!


Check this out:

save this macro in a file called loopfolder.xls
Copy all xls files to one folder.
Fill in the variables in the following:

Sub FolderLoop()

Dim pathstr, strfile As String

Application.ScreenUpdating = False

pathstr = ""
strfile = ""


pathstr = "replace with the path of the folder with all the xls"
ChDir (pathstr)
strfile = Dir("*.xls")


Do While Len(strfile) 0
On Error GoTo errortrap


Workbooks.Open (pathstr & "\" & strfile)

x = Range("a1").Value ' change it to needed cell address
y = Range("a2").Value ' change it to needed cell address
Workbooks(strfile).Close

Application.Workbooks("LoopFolder.xls").Activate

Application.Selection.Value = x
Application.Selection.Offset(0, 1).Value = y
Application.ActiveCell.Offset(1, 0).Select




ChDir (pathstr)
strfile = Dir

errortrap:
Loop
Application.ScreenUpdating = True

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How 2 import Excel file w/ multiple worksheets ??? akm Excel Discussion (Misc queries) 1 October 1st 09 10:01 PM
Import data from multiple txt files into one xls file Steve[_4_] Excel Programming 3 October 20th 07 12:08 PM
Import txt file with multiple rows for each record VanessaNY Excel Discussion (Misc queries) 4 September 15th 05 07:33 PM
Multiple .dbf File Import Help nickg420[_6_] Excel Programming 2 August 5th 04 01:16 PM
Import Text file into multiple columns Steve Excel Programming 0 October 30th 03 12:18 AM


All times are GMT +1. The time now is 10:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"