0

MY inputbox allow user to input a value into a cell. Therefore I wish to filter some input like =SUM(A:A) and ' which will show nothing, and other formula or possibly entry that will affect the actual value. Thanks in advance.

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
2
  • what type of inputbox you use? show us that simple part of your code and how you enter data later to cell Commented Apr 23, 2013 at 6:00
  • Updated code block in my question Commented Apr 23, 2013 at 6:09

1 Answer 1

1

You could use different attempts to filter some or all required values. Keep in mind that you y variable is string type. Therefore here are some of ideas with some comments:

'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

you could combine them all into one if...then statement using and or or operators.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks to your answer! I guess that filter '=' will be enough to prevent user input formula into the cell. But I was wondering why ' will not show if it is the first character.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.