2013-04-23 128 views
0

我的输入框允许用户在单元格中输入一个值。因此,我希望过滤一些输入,如=SUM(A:A)',它们不会显示任何内容,以及其他公式或可能会影响实际值的条目。提前致谢。EXCEL VBA过滤器用户输入

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 
+0

你使用什么类型的输入框?向我们展示您的代码的简单部分以及如何在以后向单元格输入数据 – 2013-04-23 06:00:01

+0

在我的问题中更新的代码块 – 2013-04-23 06:09:01

回答

1

您可以使用不同的尝试过滤部分或全部所需的值。请记住,您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 

你可以它们全部组合成使用andor运营商一个if...then声明。

+0

感谢您的回答!我想过滤器'='将足以阻止用户输入公式进入单元格。但我想知道为什么'不会显示它是否是第一个字符。 – 2013-04-23 06:31:55