[英]EXCEL VBA Filter user input
我的輸入框允許用戶將值輸入到單元格中。 因此,我希望過濾一些輸入,例如=SUM(A:A)
和'
,它們將什么也不顯示,以及其他將影響實際值的公式或可能的輸入。 提前致謝。
Private Sub testInputBox_Click()
Dim x As String
Dim y As String
Dim yDefault As String
Dim found As Range
x = InputBox("Enter Parts No.", "Edit Description")
If (x <> "") Then
If (WorksheetFunction.CountIf(Worksheets("Sheet1").Range("E2:E27"), x) > 0) Then
Set found = Worksheets("Sheet1").Range("E2:E27").Find(x, LookIn:=xlValues)
yDefault = found.Offset(0, 1).Text
y = InputBox("Amend Description", "Edit Description", yDefault)
Else
MsgBox ("Not found!")
End If
If (y <> "") Then 'Filter should be done here
If MsgBox("Proceed to edit?", vbYesNo, "Confirmation") = vbNo Then
Else
found.Offset(0, 1).Value = CStr(y)
End If
End If
End If
End Sub
您可以嘗試使用不同的方法來過濾某些或所有必需的值。 請記住,您y variable
是字符串類型。 因此,這里有一些想法和一些評論:
'tests for starting characters
If y <> "'" And y <> "=" Then
'test for formulas
If UCase(Left(y, 4)) <> "=SUM" Then
'test for any string within other string
If InStr(1, y, "sum", vbTextCompare) = 0 Then
'...here your code
End If
End If
End If
您可以將它們全部組合為一個, if...then
使用and
或or
運算符if...then
聲明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.