+ Reply to Thread
Results 1 to 4 of 4

values in a text box

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-12-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    263

    values in a text box

    Hi all

    I have a text box and a command button, if i pass some specific values it will give me a message
    but when the given value is entered it states " run time error, mismatch ". my code is below

    should i change the text properties ?? let me know whats wrong with the two codes below

    Private Sub CommandButton1_Click()
    If TextBox1.Value = Application.WorksheetFunction.Trim("abc") Or _
    Application.WorksheetFunction.Trim("def") Then
    
    MsgBox "123"
    
    End If

    
    Private Sub CommandButton1_Click()
    If TextBox1.Value = "123" Or "456" Then
    MsgBox "abc"
    End If
     "The problem with this code for any number it is giving the message "abc"
    which should not be the case. should message only for 123/456
    
    Never confuse a single defeat to the final defeat.

  2. #2
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: values in a text box

    Hi grkchakri

    Check the below changes to the code, it will resolve your problem.

    If TextBox1.Value = "123" Or TextBox1.Value = "456" Then

  3. #3
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: values in a text box

    Like this.....
    Private Sub CommandButton1_Click()
    If TextBox1.Value = 123 Or TextBox1.Value = 456 Then
    MsgBox "abc"
    End If
    End Sub
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  4. #4
    Valued Forum Contributor Miroslav R.'s Avatar
    Join Date
    05-16-2013
    Location
    NMnV, Slovakia
    MS-Off Ver
    Excel 2007
    Posts
    479

    Re: values in a text box

    Hi there,
    also You should distinguish between Textbox1.Value and Textbox1.Text in case of '123' and 'abc'.
    Regards
    Miroslav R.

    (If You like my solutions, feel free to add reputation.)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 06-25-2012, 02:10 PM
  2. Replies: 2
    Last Post: 06-13-2012, 11:20 AM
  3. Replies: 1
    Last Post: 05-02-2011, 03:48 PM
  4. Macro to special paste dynamic values into text values with periods
    By iyudhi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-01-2011, 04:42 PM
  5. Adding text values and date values to get a single-digit answer
    By e4excel in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 11-24-2008, 12:53 AM

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