+ Reply to Thread
Results 1 to 12 of 12

The "=" character ban

  1. #1
    Registered User
    Join Date
    02-12-2006
    Posts
    54

    The "=" character ban

    Hello

    How do I NOT allow the user to type the equal sign as being the first character of his input in a certain cell?

    For example:

    How can I forbit the user to input such as: "=A1+A2"

    I want him to put plain text or number, and not formula to avoid screwing my VBA code

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Try

    =NOT(A1="=")

    PS How many more have you got

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    02-12-2006
    Posts
    54
    what you're suggesting here is that if the cell only contained the "=" char, but what I'm saying here is that I don't want the user to put any formula such as:

    =SUM()
    =AND()
    =OR()
    .
    .
    .

    So, how do I go about this matter?

    Is there a function that checks the first char in a cell?

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Don't think you can stop them entering a formula. You could maybe use a event procedure to convert the User enter to a value.

    VBA Noob

  5. #5
    Registered User
    Join Date
    08-17-2004
    Posts
    10
    You could use Data Validation to allow them to only enter a number, not sure how you can allow text as well though.

  6. #6
    Registered User
    Join Date
    11-04-2006
    Posts
    30
    Try this in data validation...

    =NOT(LEFT(A1,1)="=")

  7. #7
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    vbace2,

    Doesn't stop formula's

    Left function doesn't work until you hit ok and then it doesn't see the = when it's in a formula

    VBA Noob

  8. #8
    Registered User
    Join Date
    11-04-2006
    Posts
    30
    You said you want the user to be able to add numbers or text, but not the equal sign. If numbers are entered, are the numbers going to be used in calculations?

    You could format the cells as text, and then use validation and say =NOT(LEFT(A1,1)="=")

  9. #9
    Registered User
    Join Date
    02-12-2006
    Posts
    54
    VBA Noob is right, I tried your way vbace2 by entering in the validation of A1 what you suggested, then I tested it as follows:

    I entered the "=" as the first char and it successfully restricted it

    Then...

    I entered the "=" as the first char and followed it with some testing string that doesn't refer to any function name such as "=testing" and it restricted it successfully too.


    So far so good

    However, when I entered the following in A1:

    Please Login or Register  to view this content.
    it didn't restrict it and it calculated the sum of both A3 & B3 and placed the result in A1

  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,624
    The following code seems to work; however, it gives the error message twice...
    PHP Code: 
    Option Explicit
    Public previouscell As String
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
            If 
    previouscell "" Then
                    
    If Range(previouscell).HasFormula True Then
                            Range
    (previouscell).Select
                            MsgBox 
    "formulas not allowed"
                    
    End If
            
    End If
            
    previouscell Target.Address
    End Sub 
    Ben Van Johnson

  11. #11
    Registered User
    Join Date
    02-12-2006
    Posts
    54
    protonLeah you're the man, thanks, your code worked just fine

    thanks again and thans to all who put their effort to help me out finding the solution around this matter

  12. #12
    Forum Contributor
    Join Date
    07-05-2006
    Location
    Canada
    MS-Off Ver
    2003, 2007
    Posts
    581
    You can probably get rid of the duplicate message by adding the following:

    Please Login or Register  to view this content.
    Scott

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1