Sub or Function not defined

jfabro

New Member
Joined
May 25, 2014
Messages
10
Hello again.
I am running into a compile error saying “Sub or Function Not Defined” for the following:
LastRowInOneColumn
Could you please help me out!
Here is my code:

Range(strCopyRange).Select
Selection.Copy
currentWB.Activate
Sheets(strWhereToCopy).Select
LastRow = LastRowInOneColumn(STOCK#)
Cells(LastRow + 1, 1).Select
Selection.PasteSpecial xlPasteValues, xlPasteSpecialOperationNone
Application.CutCopyMode = False
dataWB.Close False
Sheets(strListSheet).Select
ActiveCell.Offset(1, 0).Select
Loop


Thank you again for your assistance.

JFabro
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Do you have a sub/function named LastRowInOneColumn?
 
Upvote 0
Here is the complete code:
Sub GetData()
Dim strWhereToCopy As String, strStartCellColName As String
Dim strListSheet As String
strListSheet = "LIST"
On Error GoTo ErrH
Sheets(strListSheet).Select
Range("B2").Select
'this is the main loop, we will open the files one by one and copy their data into the masterdata sheet
Set currentWB = ActiveWorkbook
Do While ActiveCell.Value <> ""
strFileName = ActiveCell.Offset(0, 1) & ActiveCell.Value
strCopyRange = ActiveCell.Offset(0, 2) & ":" & ActiveCell.Offset(0, 3)
strWhereToCopy = ActiveCell.Offset(0, 4).Value
strStartCellColName = Mid(ActiveCell.Offset(0, 5), 2, 1)
Application.Workbooks.Open strFileName, UpdateLinks:=False, ReadOnly:=True
Set dataWB = ActiveWorkbook
Range(strCopyRange).Select
Selection.Copy
currentWB.Activate
Sheets(strWhereToCopy).Select
LastRow = LastRowInOneColumn("STOCK#")
Cells(LastRow + 1, 1).Select
Selection.PasteSpecial xlPasteValues, xlPasteSpecialOperationNone
Application.CutCopyMode = False
dataWB.Close False
Sheets(strListSheet).Select
ActiveCell.Offset(1, 0).Select
Loop
Exit Sub
ErrH:
MsgBox "It seems some file was missing. The data copy operation is not complete."
Exit Sub
End Sub

It does look like there may be a missing Sub but where would i insert it?
 
Upvote 0
It does look like there may be a missing Sub but where would i insert it?
You are missing a Function, not a Sub. But even if you supply the function, you will have another problem with that line of code... you do not have any lines of code assigning a value to STOCK# which is to be passed into the function. Do you have or know the column letter or column number (either would work) that STOCK# should be assigned?
 
Upvote 0
Wow, yes the column would be "B" or 2. and the Function?
Actually, I do not think you need a function, rather, I think you can do it inline with normal VB code. You are looking for the last row with data in Column B, correct? Try replacing the line of code that is causing the error with this one..

LastRow = Cells(Rows.Count, "B").End(xlUp).Row

Note: I have not looked at the rest of your code for correctness of operation... I simply gave you an inline method to calculate the late data row in a given column.
 
Upvote 0
Thank you, that worked. Now if I can just get the files to open correctly I will be done.
 
Upvote 0
What do you mean 'correctly?

Are you having problems with opening the files, or how the code is referring to the files you are opening?
 
Upvote 0
I was having issues getting the file to open at all. I have managed to fix the issue and the Macro works.
Thank you for all your assistance.
 
Upvote 0

Forum statistics

Threads
1,215,328
Messages
6,124,299
Members
449,149
Latest member
mwdbActuary

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