excel - 提示用户选择一个单元格,从该单元格获取和存储字符串
问题描述
基本上我正在尝试从用户选择的单元格中获取一个字符串并存储该字符串以供以后使用。
目前,我在现有循环中多次使用此功能。它第一次工作,然后就失败了。我想将用户选择的单元格中包含的字符串存储为单独的字符串变量 sCell。
Dim vendor As String, sCell As String
vendor = "New Test Vendor 8675309"
pInput = vendor & " does not appear in Vendor Database." & vbNewLine & vbNewLine & "Does " & vendor & " already exist?" & vbNewLine & vbNewLine & _
"If yes, please select the Vendor Number that " & vendor & " belongs to." & vbNewLine & vbNewLine & _
"Otherwise, please select a cell that says " & """" & "Does not Exist" & """" & "."
sCell = Application.InputBox(pInput)
执行宏后,第二次出现运行时错误类型不匹配。有小费吗?
解决方案
如果你想要一个范围,你应该Dim
把你的变量作为一个范围
尝试:
Dim vendor As String
Dim sCell As Range
vendor = "New Test Vendor 8675309"
pInput = vendor & " does not appear in Vendor Database." & vbNewLine & vbNewLine & "Does " & vendor & " already exist?" & vbNewLine & vbNewLine & _
"If yes, please select the Vendor Number that " & vendor & " belongs to." & vbNewLine & vbNewLine & _
"Otherwise, please select a cell that says " & """" & "Does not Exist" & """" & "."
Set sCell = Application.InputBox(Prompt:=pInput, Type:=8)
要获取地址,请使用sCell.Address
,对于值,请使用sCell.Value
推荐阅读
- python - 获取滚动窗口是增加还是减少
- python-3.x - 矢量化标记法文文本
- python - 逐行读取文本文件并计算一行中具有特定值的特定单词
- css - Bootstrap v3 hidden-* 特定断点宽度处的错误
- jquery - 我想每次都更新结果,但不明白我该怎么做
- kubernetes - 如何将所有证书从一台服务器上的 Kubernetes 复制到另一台服务器上的 Kubernetes?
- c - 为什么指针只增加一次
- c++ - 使用 set 方法从未排序的数组中删除重复项
- data-structures - 如何处理 ECS 中的动态分层实体
- android - Unity 2018 或 2019 减小 APK 或 .ipa 文件的大小