Compiler mistaking function return statement as undeclared variable

dmqueen

Board Regular
Joined
Aug 5, 2014
Messages
53
I'm used to Implicit Return statements, so I'm probably doing this wrong. My compiler gives me a Variable not defined error for my return statement for my function. Someone please take a look and let me know what I've got wrong in my return stmt? Bless you!
<code>
Public Function fGenerateNextPartNumber(LastPartIn As String) As String
Dim LastPartNO As String
LastPartNO = LastPartIn
'LastPartNo = ActiveCell.Value
Dim NewStrPartNo As String
Dim strseparator As String

Dim strPartNo As String
Dim strLastPartNo As String

strPartNo = ActiveSheet.Name()
Dim strSeperator As String
Dim strLastSeqPartNo As String
strLastPartNo = (Right(LastPartIn, 4))
'debugging
Call MsgBox(LastPartNO)

Dim strNewSeqPartNo As String
Dim intNewSeqNo As Integer

Dim intLastSeqNo As Integer
'handle special case separators HERE!
Dim lastseqNo As Integer

intLastSeqNo = CInt(strLastPartNo)
intNewSeqNo = lastseqNo + 1
'debugging
Call MsgBox(strPartNo)
If strPartNo = "180" Or strPartNo = "300" Or strPartNo = "310" Or strPartNo = "320" Or strPartNo = "330" Or strPartNo = "970" Or strPartNo = "681" Or strPartNo = "981" Then
strseparator = "-1-"

Else: strseparator = "-0-"
End If

NewStrPartNo = strPartNo + strseparator + CStr(intNewSeqNo)

'return statement
fGenerateNextPartNo = NewStrPartNo

End Function
</code>

I've tried creating the string in the return stmt instead of in NewstPartNo first, to no avail.:confused:
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Your function is called fGenerateNextPartNumber and you're assigning a value to fGenerateNextPartNo . Change the "No" at the end to "Number" and see if you're good.....
 
Upvote 0
Beautiful! That's what I get for calling it an abbrev and changing it. Thank you JerH! I love you! :)
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,637
Latest member
Ezio2866

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