I am trying to take some data out of a couple hundred sheets. Basically I open each one by one pull the key data and find the last available cell in column D as the start point to paste to from the next file. It seems to keep selecting row 23 (even though the cells up to 2 are empty) and then the next file starts on line 76 leaving a bunch of empty space. I have no idea why it seems to be selecting these cells no matter what I do. I have gone line by line and it seems to loop through the files correctly and grab the correct info, just pastes it in the wrong location. Any help would be appreciated. Thanks.
Code:
Sub Copy_Info()
Dim MainWkbk As Workbook
Dim NextWkbk As Workbook
Dim folderPath As String
Dim filename As String
Dim wb As Workbook
Set MainWkbk = ActiveWorkbook
folderPath = "C:\Users\f18023b\Documents\Test\" 'change to suit
If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"
filename = Dir(folderPath & "*.xls")
Do While filename <> ""
Application.ScreenUpdating = False
Set wb = Workbooks.Open(folderPath & filename)
'Open one File
Set NextWkbk = ActiveWorkbook
lmaxrows = Cells(Rows.Count, "D").End(xlUp).Row
NextWkbk.Activate
Sheets("Inputs").Select
Range("B3").Select
Selection.Copy
Windows("TSM Rollup .xlsm").Activate
Range("A" & lmaxrows + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
NextWkbk.Activate
Range("B4").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TSM Rollup .xlsm").Activate
Range("B" & lmaxrows + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
NextWkbk.Activate
Range("B5:E5").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TSM Rollup .xlsm").Activate
Range("C" & lmaxrows + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
NextWkbk.Activate
Sheets("2015 Plan").Select
Range("A63:A77").Select
Application.CutCopyMode = False
Selection.Copy
Windows("TSM Rollup .xlsm").Activate
Range("D" & lmaxrows + 1).Select
ActiveSheet.Paste
NextWkbk.Activate
ActiveWorkbook.Close False
filename = Dir
Loop
Application.ScreenUpdating = True
End Sub