GuyFromStl
New Member
- Joined
- Sep 8, 2012
- Messages
- 18
First, thanks for everyone who helped provide code to consolidate files into a single folder. I would like to take this a step further if possible.
Each month there will be a number of directories which will vary but the naming convention will be the same
Example for August:</SPAN>
S01234.FY14.Aug
S02345.FY14.Aug
S03456.FY14.Aug</SPAN>
Example for September:</SPAN>
S01234.FY14.Sep
S02345.FY14.Sep
S03456.FY14.Sep
I would then like to be able to execute the marco at the start of each month to consolidate the files by month together. I envision this by either having a pop-up box asking for the 3 digit month or manually changing the code to reflect the month needed to pull.
The code I have so far is:</SPAN>
Dim sh As Worksheet, lr As Long, fPath As String, wb As Workbook, sh2 As Worksheet, fNm As String
Dim lstRw As Long, rng As Range
Set sh = Sheets(1) 'Edit name of master sheet
fPath = "C:\temp" 'Edit directory path
If Right(fPath, 1) <> "\" Then
fPath = fPath & "\"
End If
fNm = Dir(fPath & "*.xl*")
Do
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row 'Assumes Col A will be posting reference
Set wb = Workbooks.Open(fPath & fNm)
Set sh2 = wb.Sheets(1)
lstRw = sh2.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh2.Range("A2:A" & lstRw)
rng.EntireRow.Copy sh.Range("A" & lr + 1)
wb.Close False
fNm = Dir
Loop While fNm <> ""
Each month there will be a number of directories which will vary but the naming convention will be the same
Example for August:</SPAN>
S01234.FY14.Aug
S02345.FY14.Aug
S03456.FY14.Aug</SPAN>
Example for September:</SPAN>
S01234.FY14.Sep
S02345.FY14.Sep
S03456.FY14.Sep
I would then like to be able to execute the marco at the start of each month to consolidate the files by month together. I envision this by either having a pop-up box asking for the 3 digit month or manually changing the code to reflect the month needed to pull.
The code I have so far is:</SPAN>
Dim sh As Worksheet, lr As Long, fPath As String, wb As Workbook, sh2 As Worksheet, fNm As String
Dim lstRw As Long, rng As Range
Set sh = Sheets(1) 'Edit name of master sheet
fPath = "C:\temp" 'Edit directory path
If Right(fPath, 1) <> "\" Then
fPath = fPath & "\"
End If
fNm = Dir(fPath & "*.xl*")
Do
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row 'Assumes Col A will be posting reference
Set wb = Workbooks.Open(fPath & fNm)
Set sh2 = wb.Sheets(1)
lstRw = sh2.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh2.Range("A2:A" & lstRw)
rng.EntireRow.Copy sh.Range("A" & lr + 1)
wb.Close False
fNm = Dir
Loop While fNm <> ""