Results 1 to 10 of 10

textbox change

This is a discussion on textbox change within the Excel Questions forums, part of the Question Forums category; How can I allow a textbox to only be changed when another cell has a certain value? Here is what ...

  1. #1
    Board Regular
    Join Date
    Dec 2002
    Posts
    65

    Default textbox change

    How can I allow a textbox to only be changed when another cell has a certain value?

    Here is what I have so far that doesn't work:

    Private Sub TextBox4_Change(ByVal Target As Range)
    If Intersect(Target, Range("E7")) Is Nothing Then
    MsgBox "Please Enter Date"
    TextBox4.Value = ""
    End If

  2. #2
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    64,592

    Default

    Like this?

    Code:
    Private Sub TextBox4_Change()
        Static Disable As Boolean
        If Disable = True Then Exit Sub
        If IsEmpty(Range("E7")) Then
            Disable = True
            TextBox4.Value = ""
            Disable = False
            Range("E7").Select
            MsgBox "Please Enter Date"
        End If
    End Sub

  3. #3
    Board Regular
    Join Date
    Dec 2002
    Posts
    65

    Default

    when I enter a value into the textbox the msg does not come up even when there is nothing in cell E7

  4. #4
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    64,592

    Default

    It worked for me, with a TextBox from the Control ToolBox on the same worksheet as cell E7. What's your setup?

  5. #5
    Board Regular
    Join Date
    Dec 2002
    Posts
    65

    Default

    I am using a textbox from the drawing toolbar

  6. #6
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    64,592

    Default

    Well that explains why it doesn't work. It's best to use one from the Control Toolbox.

  7. #7
    Board Regular
    Join Date
    Dec 2002
    Posts
    65

    Default

    When I use one from the control toolbox, I cannot insert text

  8. #8
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    64,592

    Default

    After adding it right click and choose View Code. Paste my code in the window on the right (excluding the first and last lines which are already there). Press Alt+F11 to return to your worksheet and click the Design icon (top left of Control Toolbox) to exit Design mode.

  9. #9
    Board Regular
    Join Date
    Dec 2002
    Posts
    65

    Default

    OK,
    now what if I wanted to do the same thing with 2 textboxes instead of a textbox and a cell.
    something like this?->

    Static Disable As Boolean
    If Disable = True Then Exit Sub
    If IsEmpty(TextBox2) Then
    Disable = True
    TextBox3.Value = ""
    Disable = False
    TextBox2.Select
    MsgBox "Please Enter Date"

    End If

  10. #10
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    64,592

    Default

    Similar:

    Code:
    Private Sub TextBox3_Change()
        Static Disable As Boolean
        If Disable = True Then Exit Sub
        If TextBox2.Value = "" Then
            Disable = True
            TextBox3.Value = ""
            Disable = False
            TextBox2.Activate
            MsgBox "Please Enter Date"
        End If
    End Sub

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com