Trouble passing workbook and worksheet variables to a subroutine

TLA

Board Regular
Joined
Jul 15, 2003
Messages
127
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
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Perhaps

Code:
Set myFile = Workbooks.Open(Fpath & "\" & myFile.Name)
Call CompileSerials(myFile.Name, BaseSheet, BaseBook)
 
Upvote 0
Remove the parentheses around the arguments.

By the way you might need to be careful what you are passing for the myFileName argument.

That really depends on how you are going to use it in subsequent code of course.:)
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,877
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top