VBA If OR stmt encounteringsyntax error

dmqueen

Board Regular
Joined
Aug 5, 2014
Messages
53
Please help!
I am trying to generate new part numbers which include a separator which is usually -0-, but n 9 special cases is -1-. I've tried putting the special cases in an If OR stmt. with and without repeating the testing field but can't get past a syntax error! Here is my function:


Public Function fGenerateNextPartNumber(LastPartIn As String) As String
Dim LastPartNo As String
LastPartNo = LastPartIn
'LastPartNo = ActiveCell.Value
Dim NewStrPartNo As String

Dim strPartNo As String
strPartNo = ActiveSheet.Name()
Dim strSeperator0 As String
Dim strSeperator1 As String
Dim strLastSeqPartNo As String
'debugging
Call MsgBox(LastPartIn)
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!
intLastSeqNo = CInt(strLastPartNo)
intNewSeqNo = LastSeqNo + 1

If strPartNo ="180" OR "300" OR = 310" OR = "320" OR "330" OR "970" OR = "681" OR "981" Then
StrSeparator = "-1-"

Else: StrSeparator = "-0-"
End If

NewStrPartNo = strPartNo + StrSeparator + CStr(intNewSeqNo)

Return NewStrPartNo

End Function


I've also tried the line:
If strPartNo ="180" OR strPartNo = "300" OR strPartNo = "310" OR =strPartNo = "320" OR strPartNo = "330" OR "strPartNo =970" OR = strPartNo ="681" OR strPartNo = "981"

But got the same error Argh!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi

try rejigging the "OR" statment to include the StrPartNo each time.

Question is the 300 numbers really text, if not remove the speech commas.

Code:
If strPartNo ="180" OR strPartNo = "300" then

regards

Kev
 
Upvote 0
unless i'm blind, I dont see strPartNo assigned to anything before the if statement. it's empty.

Also, I feel like the end of the function has to end with the name of the function (fgeneratenextpartno) = something.
I'm pretty new with this stuff but, I think that's how it works.
 
Upvote 0
I now see that you posted an attempt at Kev's suggestion.
But it has a few errors
I've also tried the line:
If strPartNo ="180" OR strPartNo = "300" OR strPartNo = "310" OR =strPartNo = "320" OR strPartNo = "330" OR "strPartNo =970" OR = strPartNo ="681" OR strPartNo = "981"
And it should have a "then" at the end..

Try it like

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
 
Upvote 0
I now see that you posted an attempt at Kev's suggestion.
But it has a few errors

And it should have a "then" at the end..

Try it like

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

Thanks Jon.
I've got it I as 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
But still receive a synteax error when I try to compile the project or run the code. :(
 
Upvote 0
It is assigned the value of the worksheet name:
strPartNo = ActiveSheet.Name()
which is also the client's part type, before testing.
I'm not super familiar with VBA either, which is why I' here :)
t
'
s
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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