+ Reply to Thread
Results 1 to 6 of 6

Enable and disable

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-14-2010
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    155

    Smile Enable and disable

    Dear Moderators,
    I have a question that I made a user formwith textbox1 and textbo2, whatever i am entering in textbox1, the same thing is available in my activesheet. i want that when i will enter in textbox1 and before entering in textbox2, macro check textbox1.value in activesheet column-a, if the same data listed in column a, it allow to enter in textbox2 otherwise some errmsg should apper.
    Hoping fot early reply and many many thanks in advance

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Enable and disale

    Hi rajeev.raj

    I'm not a Moderator but perhaps this will help
    Public Sub FindTextBoxValue()
        Dim strFind As String
        Dim rSearch As Range  'range to search
        Dim MyData As Range
     
        Set MyData = Sheet1.Range("A1").CurrentRegion
        If Not UserForm1.TextBox1 = "" Then
            Set rSearch = MyData.Columns(1)
            strFind = UserForm1.TextBox1.Value    'what to look for
     
            With rSearch
                Set c = .Find(strFind, LookIn:=xlValues, LookAt:=xlWhole)
                If Not c Is Nothing Then    'found it
                    UserForm1.TextBox2.Enabled = True
                Else: MsgBox strFind & " not listed"    'search failed
                    UserForm1.TextBox2.Enabled = False
                End If
            End With
        End If
    End Sub
    You'll need to determine how to call the procedure based on the structure of your application.
    John
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Enable and disable

    Perhaps something like
    Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
        Cancel = Not (TextBox2.Enabled)
        If Cancel Then MsgBox "Enter a value from column A"
    End Sub
    
    Private Sub TextBox1_Change()
        TextBox2.Enabled = IsNumeric(Application.Match(TextBox1.Text, ActiveSheet.Range("A:A"), 0))
    End Sub
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Forum Contributor
    Join Date
    05-14-2010
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    155

    Re: Enable and disable

    I am unable to do the same, can u please send one example worksheet using above code.

    Thanks

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Enable and disable

    I modified the code a bit.
    In the attached, press the button and the userform will appear. The second textbox will be visible only if the first textbox has an entry from column A.
    Dim Closing As Boolean
    
    Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
        Cancel = Not (TextBox2.Visible)
        If Cancel And Not Closing Then MsgBox "Enter something from column A."
    End Sub
    
    Private Sub TextBox1_Change()
        TextBox2.Visible = IsNumeric(Application.Match(TextBox1.Text, ThisWorkbook.Sheets("Sheet1").Range("A:A"), 0))
    End Sub
    
    Private Sub UserForm_Initialize()
        TextBox2.Visible = IsNumeric(Application.Match(TextBox1.Text, ThisWorkbook.Sheets("Sheet1").Range("A:A"), 0))
    End Sub
    
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
        Closing = True
    End Sub
    
    Private Sub CommandButton1_Click()
        Unload Me
    End Sub
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    05-14-2010
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    155

    Re: Enable and disable

    Thanks a lot for your early help
    Regards,

+ 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