VBA Invalid Qualifier Error

dmqueen

Board Regular
Joined
Aug 5, 2014
Messages
53
I'm eceiving an Invalid Qualifier Error for LastPartNo in Sub InputPart, even though I have clearly defined it as an Integer before I tried to use it.
I attempted dding a Temp Str type as a go between in case of a type mismatch. Still no luck. Ay help would be much apreciated! :)

lSub fInputPart()

'col A
'add a new row
'get last PartNo.
'add 1
'generate new part no.
CurrentWorksheet.Range("a5").Select
' goto the top entry ready to insert the new entry
Selection.End(xlDown).Select
Selection.End(xlUp).Select
ActiveCell.Offset(-2, 0).Active
If ActiveCell.Value = "=" Then
Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
Range("A" & ActiveCell.Row).Select
Else
End If
'Goto last part number
ActiveCell.Offset(-1, 0).Activate
Dim LastPartNO As Integer
'Next 4 lines added to try 2 clear invalid qualifier error
Dim TempLastPartNumber As String
TempLastPartNo = fGenerateNextPartNumber(Range(Active.Cell.Select).Value)
LastPartNO = CInt(TempLastPartNo)
Dim NewPartNo As Integer

'Get the last part number here!!
NewPartNo = LastPartNO.Value + 1
Selection.End(xlUp).Select
Call MsgBox("Last Part No is" & ActiveCell.Value, vbInformation, Application.Name)

Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
Range("A" & ActiveCell.Row).Select
''Put the new part number here!!
ActiveCell.Value = fGenerateNextPartNumber(ActiveCell.Value)
'go to next col
'col B
Range("B" & ActiveCell.Row).Select
'verify entry was made
'go to next col
'while there are columns for data entry (has column title) verify entry was made in last column,
'error msg if not,
'go to next column if made
While (Row5 & ActiveCell.Column <> "")
'while there are columns left for entry: there is a column header
'go to the next column for entry that is active and has a width not equal to 1
'verify entry was made in last column: holler and stop if not: continue if made
If ActiveCell.Offset(0, -1) = Null Then
Call MsgBox("Please enter/select a value in the previous column! ", vbExclamation, Application.Name)

Else
'if inactive(width=1, jump it, else stop for entry
If ActiveCell.Offset(0, 1).ColumnWidth = 1 Then
ActiveCell.Offset(0, 2).Activate
Else: ActiveCell.Offset(0, 1).Activate
End If
End If
Wend
Call MsgBox("Entry Complete, thank you! Don't forget to save when done! :)", vbInformation, Application.Name)
End Sub
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()
'debugging
Call MsgBox(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
'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)
fGenerateNextPartNo = NewStrPartNo

End Function
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hiya
Try changing
Code:
NewPartNo = LastPartNO.Value + 1
to
Code:
NewPartNo = LastPartNO + 1
HTH
 
Upvote 0
Hiya
Try changing
Code:
NewPartNo = LastPartNO.Value + 1
to
Code:
NewPartNo = LastPartNO + 1
HTH


Apart from Fluff's good advice

Code:
Dim NewPartNo As Integer
'Get the last part number here!!
NewPartNo = LastPartNO.Value + 1

Since you don't use NewPartNo what was the point?
 
Upvote 0
Apart from Fluff's good advice

Code:
Dim NewPartNo As Integer
'Get the last part number here!!
NewPartNo = LastPartNO.Value + 1

Since you don't use NewPartNo what was the point?

I have changed it per your instructions and still have the same error! :(
I had planned on using NewPartNO, but then realized I needed it as a String and haven't taken it out.
I haven't do very much of this, I wlll remove it, Thanks
 
Upvote 0
Invalid Qualifier Error gone when I removed NewPartNo! But now receiving Object Required Error- Run time 424!
 
Upvote 0
I'm eceiving an Invalid Qualifier Error for LastPartNo in Sub InputPart, even though I have clearly defined it as an Integer before I tried to use it.
I attempted dding a Temp Str type as a go between in case of a type mismatch. Still no luck. Ay help would be much apreciated! :)
<code>
lSub fInputPart()

'col A
'add a new row
'get last PartNo.
'add 1
'generate new part no.
CurrentWorksheet.Range("a5").Select
' goto the top entry ready to insert the new entry
Selection.End(xlDown).Select
Selection.End(xlUp).Select
ActiveCell.Offset(-2, 0).Active
If ActiveCell.Value = "=" Then
Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
Range("A" & ActiveCell.Row).Select
Else
End If
'Goto last part number
ActiveCell.Offset(-1, 0).Activate
Dim LastPartNO As Integer
'Next 4 lines added to try 2 clear invalid qualifier error
Dim TempLastPartNumber As String
TempLastPartNo = fGenerateNextPartNumber(Range(Active.Cell.Select).Value)
LastPartNO = CInt(TempLastPartNo)
Dim NewPartNo As Integer

'Get the last part number here!!
NewPartNo = LastPartNO.Value + 1
Selection.End(xlUp).Select
Call MsgBox("Last Part No is" & ActiveCell.Value, vbInformation, Application.Name)

Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
Range("A" & ActiveCell.Row).Select
''Put the new part number here!!
ActiveCell.Value = fGenerateNextPartNumber(ActiveCell.Value)
'go to next col
'col B
Range("B" & ActiveCell.Row).Select
'verify entry was made
'go to next col
'while there are columns for data entry (has column title) verify entry was made in last column,
'error msg if not,
'go to next column if made
While (Row5 & ActiveCell.Column <> "")
'while there are columns left for entry: there is a column header
'go to the next column for entry that is active and has a width not equal to 1
'verify entry was made in last column: holler and stop if not: continue if made
If ActiveCell.Offset(0, -1) = Null Then
Call MsgBox("Please enter/select a value in the previous column! ", vbExclamation, Application.Name)

Else
'if inactive(width=1, jump it, else stop for entry
If ActiveCell.Offset(0, 1).ColumnWidth = 1 Then
ActiveCell.Offset(0, 2).Activate
Else: ActiveCell.Offset(0, 1).Activate
End If
End If
Wend
Call MsgBox("Entry Complete, thank you! Don't forget to save when done! :)", vbInformation, Application.Name)
End Sub
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()
'debugging
Call MsgBox(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
'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)
fGenerateNextPartNo = NewStrPartNo

End Function
</code>
Compiles, but doesn't run from either he code window or the worksheet button! :(
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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