Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By AlphaFrog

If condition Failing With Textbox Value = "-"

This is a discussion on If condition Failing With Textbox Value = "-" within the Excel Questions forums, part of the Question Forums category; This code ... Code: .... If .tb_r7_srl.Value = "-" Then .tb_r7_srl.Value = "" .tb_r7_sru.Value = "" Else .... Appears to ...

  1. #1
    Board Regular
    Join Date
    Apr 2005
    Location
    Ontario, Canada
    Posts
    2,824

    Default If condition Failing With Textbox Value = "-"

    This code ...

    Code:
                ....
                If .tb_r7_srl.Value = "-" Then
                    .tb_r7_srl.Value = ""
                    .tb_r7_sru.Value = ""
                Else
                ....
    Appears to fail when the value of .tb_r7_srl.Value equals "-" WHen the value is indeed a hyphen, the code skips over to the Else condition.
    A check in the immediates window of Me.tb_r7_srl.Value returns -.

    What could be causing this?

  2. #2
    MrExcel MVP AlphaFrog's Avatar
    Join Date
    Sep 2009
    Posts
    15,383

    Default Re: If condition Failing With Textbox Value = "-"

    Possibly there is a space before or after the hyphen?

    Try this...

    Code:
    If Trim(.tb_r7_srl.Value) = "-" Then
    Ark68 likes this.
    Paste your Excel data to the forum...
    MrExcel HTML Maker or Excel Jeanie

    How to post your vba code
    [CODE]your VBA code here[/CODE]
    The # button in the forum's editor will apply CODE tags around your selected text.

  3. #3
    Board Regular
    Join Date
    Apr 2005
    Location
    Ontario, Canada
    Posts
    2,824

    Default Re: If condition Failing With Textbox Value = "-"

    Thank you Alpha!! That seems to have taken care of the problem.

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