textbox change

JL_CAD

Board Regular
Joined
Dec 29, 2002
Messages
65
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
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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
 
Upvote 0
when I enter a value into the textbox the msg does not come up even when there is nothing in cell E7
 
Upvote 0
It worked for me, with a TextBox from the Control ToolBox on the same worksheet as cell E7. What's your setup?
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,495
Messages
6,113,992
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top