+ Reply to Thread
Results 1 to 10 of 10

Condition Cell

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Condition Cell

    How can I make it so that if a user in enters t or T in a specific cell the cell automatically shows "TRUE" and if they enter f or F the cell shows "FALSE"
    I need this condition on cells in range G11:G24

    thank you for your time and help.

  2. #2
    Valued Forum Contributor
    Join Date
    10-15-2007
    Location
    Home
    MS-Off Ver
    Office 2010, W10
    Posts
    373
    Hi

    It's easier if you restrict the user input to True and False with a dropdown using a list in Data>Validation.

    If for some reason you really want to have the user input t or T and automatically change the value of the cell to True, you have to use vba. Use the worksheet Change Event.

    HTH
    lecxe

  3. #3
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299
    I would like to use the change event, but I don't know how write it.

    I have this change event I have been using but don't know how to edit it to fit my needs.

    Would you know how to change it?

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
    
        On Error Resume Next
        If Not Intersect(Target, Range("G11:G50")) Is Nothing Then
            Application.EnableEvents = False
            Target = UCase(Target)
            Application.EnableEvents = True
        End If
        On Error GoTo 0
        End Sub

  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
    Maybe

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
    
        On Error Resume Next
        If Not Intersect(Target, Range("G11:G50")) Is Nothing Then
            Application.EnableEvents = False
           Select Case UCase(Target.Value)
           Case "F"
           Target.Value = "True"
           Case "T"
           Target.Value = "False"
           Case Else
           Target.Value = UCase(Target.Value)
           End Select
            Application.EnableEvents = True
        
        End If
        On Error GoTo 0
    End Sub
    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 !!!

  5. #5
    Valued Forum Contributor
    Join Date
    10-15-2007
    Location
    Home
    MS-Off Ver
    Office 2010, W10
    Posts
    373
    Hi again

    You can complement VBA Noob's code with Data Validation in the worksheet to ensure that the user is only allowed to enter the letters f and t.

  6. #6
    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
    Or just tweak it slightly

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
    
        On Error Resume Next
        If Not Intersect(Target, Range("G11:G50")) Is Nothing Then
            Application.EnableEvents = False
           Select Case UCase(Target.Value)
           Case "F"
           Target.Value = "True"
           Case "T"
           Target.Value = "False"
           Case Else
           Application.Undo
           End Select
            Application.EnableEvents = True
        
        End If
        On Error GoTo 0
    End Sub
    VBA Noob

  7. #7
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299
    code works, but I am unable to delete the cell contents. How do I fix this??

+ 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