简体   繁体   English

VBA-输入框-用户窗体

[英]VBA - Input box - userform

This is my code: 这是我的代码:

qty = InputBox("Please enter the quantity to be added.", "Add Quantity")
Cells(row, 2) = qty
Description = InputBox("Please enter a description.", "Enter Description")
Cells(row, 3) = Description
Unitp = InputBox("Please enter a unit price.", "Enter UnitPrice")
Cells(row, 4) = Unitp
Amount = InputBox("Please enter an amount.", "Enter Amount")
Cells(row, 5) = Amount

Qty & Unitp is getting displayed correctly in Excel. 在Excel中正确显示了QtyUnitp However, when I enter characters in the Description input box then it throws an error. 但是,当我在“ Description输入框中输入字符时,它将引发错误。 But if I enter no . 但是如果我输入no it goes through but displays as FALSE in the Excel cell. 它会通过,但在Excel单元格中显示为FALSE This is the case for both Descripton & Amount . DescriptonAmount都是这种情况。

Can someone help? 有人可以帮忙吗?

You need to Declare your variables for them to take the correct input, put this above your code: 您需要声明变量以使它们接受正确的输入,并将其放在代码上方:

Dim qty as Integer
Dim Unitp as Double
Dim Description as String
Dim Amount as Integer

this issue is resolved. 这个问题已经解决。 I had declared description for some other variable. 我已经声明了一些其他变量的描述。 Just changed it form Description to Desc & like wise for Amount fields. 只是将其形式从“描述”更改为“描述”,以及“金额”字段的用法。

Worked just fine. 工作得很好。

Thanks for your help guys! 感谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM