vba 消息框中的多个变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23476991/
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
Multiple variables in a message box
提问by user3604976
I'm looking to present multiple variables into a messagebox: ID, Customer Name, Date Added, Venue and Status. At the moment, I can only get the ID to display, the other variables present a Runtime 13 Error. My code is below.
我希望在消息框中显示多个变量:ID、客户名称、添加日期、地点和状态。目前,我只能获取要显示的 ID,其他变量出现运行时 13 错误。我的代码如下。
Sub LookupTicket()
Dim ibox, tid As Range
Dim dad, sta, ven, cna As Variant
Set Sheet = Worksheets("ControlSheet")
dad = Range("DateAdded_CS").Value
sta = Range("Status_CS").Value
ven = Range("Venue_CS").Value
cna = Range("CustName_CS").Value
ibox = InputBox("Enter Ticket ID:", "Redeem Ticket")
If ibox <> "" Then
Set tid = Sheet.Range("A:A").Find(ibox)
If tid Is Nothing Then
MsgBox "Ticket ID not found!", vbCritical, "Redeem Ticket"
Else
'MsgBox "Ticket details for ID: " & tid & vbNewLine & "Date Added: " & dad & vbNewLine & "Customer Name: " & cna & vbNewLine & "Venue: " & ven & vbNewLine & "Status: " & sta, vbInformation, "Lookup Ticket Details"
MsgBox "ID: " & sta, "Lookup Ticket"
End If
End If
Thanks guys for any input.
感谢大家的任何意见。
回答by Bmo
The variable tid
is a Range. You should change that to tid.Value
if its going to have a single cell.
变量tid
是一个范围。tid.Value
如果它有一个单元格,您应该将其更改为。
edit: Check if tid.count = 1
I get a type mismatch (13) error when trying to value out of a group of cells in a range. Your Range.Find(ibox)
might be returning more than one value.
编辑:检查tid.count = 1
在尝试从范围内的一组单元格中取值时是否出现类型不匹配 (13) 错误。您Range.Find(ibox)
可能会返回多个值。