I have the following code. Don't worry too much about the compile serials code so much as I'm still working on it and I want to reference the BaseSheet and BaseBook in that routine (That were set when the macro was run from that sheet). However I am getting an "Expected =" when I try to pass the worksheet and workbook variables to the subroutine. I can pass the string no problem. Excel doesn't like the procedure call in bold when I add the last two variables.
Sub PullSerial()
Dim Msg, Fpath As String
Dim BaseSheet As Worksheet
Dim BaseBook As Workbook
Set FSO = CreateObject("Scripting.FileSystemObject")
Set BaseSheet = ActiveSheet
Set BaseBook = ActiveWorkbook
'select folder that contains datafiles
Msg = "Please select the folder that contains your data files."
Fpath = GetDirectory(Msg)
If Fpath = "" Then
MsgBox "No folder selected, cancelling summary."
End If
Set myFolder = FSO.GetFolder(Fpath)
'Open each file and pull data
For Each myFile In myFolder.Files
Workbooks.Open (Fpath & "\" & myFile.Name)
CompileSerials (myFile.Name,BaseSheet,BaseBook)
Workbooks(myFile.Name).Close
Next myFile
End Sub
Sub CompileSerials(myFileName As String, myBaseSheet As Worksheet, myBaseBook As Workbook)
MsgBox myFileName
For Each ws In Worksheets
MsgBox ws.Name
Next
GoTo Finish
MyRow = CurrentRow = BaseSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1
For i = 5 To ActiveWorkbook.Sheets.Count
For j = 8 To Sheets(i).Cells(Rows.Count, 1).End(xlUp).Row
Cells(Myrow, 1).Value = Sheets(i).Cells(j, 1).Value 'Serial
Cells(Myrow, 2).Value = Sheets(i).Cells(j, 2).Value 'SKU
Cells(Myrow, 3).Value = Sheets(i).Cells(j, 3).Value 'SKU Name
Cells(Myrow, 4).Value = Sheets(i).Cells(j, 4).Value 'Pallet
Cells(Myrow, 5).Value = Sheets(i).Cells(j, 5).Value 'Location
Cells(Myrow, 6).Value = Sheets(i).Name 'Sheet Name
Cells(Myrow, 7).Value = "=MATCH(A" & Myrow & ",A9:A" & Myrow - 1 & ",0)+8" 'Match?
Myrow = Myrow + 1
Next j
Next i
Finish: End Sub
Sub PullSerial()
Dim Msg, Fpath As String
Dim BaseSheet As Worksheet
Dim BaseBook As Workbook
Set FSO = CreateObject("Scripting.FileSystemObject")
Set BaseSheet = ActiveSheet
Set BaseBook = ActiveWorkbook
'select folder that contains datafiles
Msg = "Please select the folder that contains your data files."
Fpath = GetDirectory(Msg)
If Fpath = "" Then
MsgBox "No folder selected, cancelling summary."
End If
Set myFolder = FSO.GetFolder(Fpath)
'Open each file and pull data
For Each myFile In myFolder.Files
Workbooks.Open (Fpath & "\" & myFile.Name)
CompileSerials (myFile.Name,BaseSheet,BaseBook)
Workbooks(myFile.Name).Close
Next myFile
End Sub
Sub CompileSerials(myFileName As String, myBaseSheet As Worksheet, myBaseBook As Workbook)
MsgBox myFileName
For Each ws In Worksheets
MsgBox ws.Name
Next
GoTo Finish
MyRow = CurrentRow = BaseSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1
For i = 5 To ActiveWorkbook.Sheets.Count
For j = 8 To Sheets(i).Cells(Rows.Count, 1).End(xlUp).Row
Cells(Myrow, 1).Value = Sheets(i).Cells(j, 1).Value 'Serial
Cells(Myrow, 2).Value = Sheets(i).Cells(j, 2).Value 'SKU
Cells(Myrow, 3).Value = Sheets(i).Cells(j, 3).Value 'SKU Name
Cells(Myrow, 4).Value = Sheets(i).Cells(j, 4).Value 'Pallet
Cells(Myrow, 5).Value = Sheets(i).Cells(j, 5).Value 'Location
Cells(Myrow, 6).Value = Sheets(i).Name 'Sheet Name
Cells(Myrow, 7).Value = "=MATCH(A" & Myrow & ",A9:A" & Myrow - 1 & ",0)+8" 'Match?
Myrow = Myrow + 1
Next j
Next i
Finish: End Sub