VBA“限定符错误无效”

在这个代码上获取一个无效的限定符错误,不知道为什么。

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 

这部分显示为错误的原因

MsgBox“totalamount =”& totalamount .Value

Totalamount是一个整数 – 它不是一个对象。 一个对象就像一个范围(即:表(1)。范围(“A1”))。 对象具有属性,如value属性。 在这种情况下,所有你需要的是

 MsgBox "totalamount = " & totalamount 

只需从totalAmount.Value删除.Value

totalAmount是原始types的variables,原始variables没有方法。

 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