我有 4 个不同的单词 ( financial, location, course, professor
) 可以在文本框中输入,但是每个单词在文本框中输入时只能使用一次。
例如,我在文本框中输入这样的句子:“我有财务问题,因为我的家人面临财务问题”下面的代码将这句话处理成拆分文本。
我想要做的验证是通知用户(可能通过 msgbox),例如:
“错误 - 你必须在一个句子中只使用一次财务。”
另外,如果在一个句子中不止一次使用了course、location和professional,也应该给出一个msgbox。
Private Sub CommandButton1_Click()
Call SplitText
End Sub
Sub SplitText()
Dim WArray As Variant
Dim TextString As String
TextString = TextBox1
WArray = Split(TextBox1, " ")
If (TextString = "") Then
MsgBox ("Error: Pls Enter your data")
Else
With Sheets("DatabaseStorage")
.Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0).Resize(UBound(WArray) + IIf(LBound(WArray) = 0, 1, 0)) = Application.Transpose(WArray)
End With
MsgBox ("Successfully inserted")
End If
End Sub
试试这个:
Private Sub CommandButton1_Click()
Call SplitText
End Sub
Sub SplitText()
Dim sentence As String
Dim mycount As Long
sentence = InputBox("Enter the sentence")
mycount = UBound(Split(sentence, "financial"))
If mycount > 1 then
Msgbox "Error - you must used financial only once in a sentence"
End if
'Here the rest of the code you need
End Sub
希望能帮助到你。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句