【发布时间】:2015-05-11 18:57:51
【问题描述】:
我目前正在尝试获取用户输入并使用逗号分隔输入的每一位。目前我正在尝试使用 -
includer = CStr(InputBox("Do you have any inclusions? Separate words with commas"))
inclusion = Split(includer, ",", , vbTextCompare)
没有运气。
它不断抛出“类型不匹配”错误。
对于任何感兴趣的人,我尝试使用的完整代码是-
Option Compare Text
Public Sub Textchecker()
'
' Textchecker
'
' Keyboard Shortcut: Ctrl+h
'
Dim Continue As Long
Dim findWhat As String
Dim LastLine As Long
Dim toCopy As Boolean
Dim cell As Range
Dim item As Long
Dim j As Long
Dim x As Long
Dim sheetIndex As Long
Dim inclusion() As String
sheetIndex = 2
Continue = vbYes
Do While Continue = vbYes
findWhat = CStr(InputBox("What word would you like to search for today?"))
includer = CStr(InputBox("Do you have any inclusions? Separate words with commas"))
inclusion = Split(includer, ",", , vbTextCompare)
LastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For item = 1 To LastLine
For Each cell In Range("BY1").Offset(item - 1, 0)
If InStr(cell.Text, findWhat) <> 0 And InStr(cell.Text, inclusion(x)) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Sheets(sheetIndex).Name = UCase(findWhat) + "+" + LCase(inclusion(x))
Rows(item).Copy Destination:=Sheets(sheetIndex).Rows(j)
j = j + 1
End If
toCopy = False
Next item
sheetIndex = sheetIndex + 1
Continue = MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion)
Loop
End Sub
【问题讨论】:
-
当您的用户 ESC 退出您的
InputBox时也会爆炸 -
我没有任何问题,请问您为什么这么说?
-
嗯,VB 必须对空字符串指针进行字符串合并。
标签: vba