Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA "Invalid Qualifier Error"

Tags:

excel

vba

Getting an Invalid Qualifier Error on this code, have no idea why.

Dim WTotal As Integer
WTotal = InputBox("Enter the amount of Wash")
Dim Startpoint As Range
Dim totalamount As Integer

Sheets("Sheet2").Select
Set Startpoint = ActiveSheet.Cells.Find(What:="Wash")
Startpoint.Offset(1, 0).Select
Range(Selection, Selection.End(xlDown)).Select
totalamount = Selection.Count

MsgBox "totalamount = " & totalamount.Value 

This part shows up as the cause of the Error

MsgBox "totalamount = " & totalamount.Value

like image 656
VBAnoob Avatar asked Dec 20 '22 01:12

VBAnoob


2 Answers

Totalamount is an integer - it is not an object. An object is something like a range (ie: sheets(1).Range("A1")). Objects have properties, such as the value property. In this case, all you need is

MsgBox "totalamount = " & totalamount
like image 90
Grade 'Eh' Bacon Avatar answered Dec 28 '22 00:12

Grade 'Eh' Bacon


Just remove .Value from totalAmount.Value.

totalAmount is a variable of primitive type and primitive variables have no methods.

Dim WTotal As Integer
WTotal = InputBox("Enter the amount of Wash")
Dim Startpoint As Range
Dim totalamount As Integer

Sheets("Sheet2").Select
Set Startpoint = ActiveSheet.Cells.Find(What:="Wash")
Startpoint.Offset(1, 0).Select
Range(Selection, Selection.End(xlDown)).Select
totalamount = Selection.Count

MsgBox "totalamount = " & totalamount
like image 23
mielk Avatar answered Dec 28 '22 00:12

mielk