VBA“无效的限定符错误”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31944210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:53:07  来源:igfitidea点击:

VBA "Invalid Qualifier Error"

excelvba

提问by VBAnoob

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

MsgBox "totalamount = " & totalamount.Value

回答by Grade 'Eh' Bacon

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

Totalamount 是一个整数 - 它不是一个对象。对象类似于范围(即:sheets(1).Range("A1"))。对象具有属性,例如 value 属性。在这种情况下,您只需要

MsgBox "totalamount = " & totalamount

回答by mielk

Just remove .Valuefrom totalAmount.Value.

只需.ValuetotalAmount.Value.

totalAmountis a variable of primitive type and primitive variables have no methods.

totalAmount是原始类型的变量,原始变量没有方法。

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