none
not equal to vba code

    Question

  • If (StrComp(TextBox4.Text, xlsh.Cells(M, 5), vbTextCompare) = 0) Then

    msg ("true"

    ElseIf (StrComp(TextBox4.Text, xlsh.Cells(M, 5), vbTextCompare) = 0) Then --here how to give not equal

    msg("false")

    End If

     

     

    Thursday, October 06, 2011 7:14 AM

All replies

  • If (StrComp(TextBox4.Text, xlsh.Cells(M, 5), vbTextCompare) = 0) Then

    msg ("true"

    ElseIf (StrComp(TextBox4.Text, xlsh.Cells(M, 5), vbTextCompare) = 0) Then --here how to give not equal

    msg("false")

    End If

     

     


    Use one of the other approaches you were given in the other discussion.  Either use Option Compare Text at the top of the code module and then use TextBox4.Text<>xlsh.Cells(M,5).Value or use UCase(TextBox4.Text))<>UCase(xlsh.Cells(M,5).Value)
    Tushar Mehta (Technology and Operations Consulting)
    www.tushar-mehta.com (Excel and PowerPoint add-ins and tutorials)
    Microsoft MVP Excel 2000-Present
    Thursday, October 06, 2011 8:38 AM
  • If (StrComp(TextBox4.Text, xlsh.Cells(M, 5), vbTextCompare) = 0) Then

    msg ("true"

    ElseIf (StrComp(TextBox4.Text, xlsh.Cells(M, 5), vbTextCompare) = 0) Then --here how to give not equal

    msg("false")

    End If

     

     


    Hi, you don't need to put in the not equal check  :)

     

    If (StrComp(TextBox4.Text, xlsh.Cells(M, 5), vbTextCompare) = 0) Then

        msg ("true")

    Else

        msg("false")

    End If


    "The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castles in the air, from air, creating by exertion of the imagination." - Fred Brooks
    Thursday, October 06, 2011 8:45 AM
  • For M = 2 To 50 Step 1

    If (StrComp(TextBox4.Text, xlsh.Cells(M, 5), vbTextCompare) = 0) Then

     TextBox1.Text = xlsh.Cells(M,6)

    ElseIf UCase(TextBox4.Text))<>UCase(xlsh.Cells(M,5).Value) Then

    TextBox1.Text = xlsh.Cells(M,8)

    End If

    Next M

     

    I used above code, but code directly go to the else if condition. not check first if condition.

    Thursday, October 06, 2011 9:15 AM
  • hi,

    For M = 2 To 50 Step 1

    If (StrComp(TextBox4.Text, xlsh.Cells(M, 5), vbTextCompare) = 0) Then

    TextBox1.Text = xlsh.Cells(M,6)

    ElseIf UCase(TextBox4.Text))<>UCase(xlsh.Cells(M,5).Value) Then

    TextBox1.Text = xlsh.Cells(M,8)

    End If

    Next M

     

    I used above code, but code directly go to the else if condition. not check first if condition.

    Thursday, October 06, 2011 9:15 AM
  • Hi,

    Make sure that the text in the cell doesn't have a leading ' character. If it does then there will be no match as it's unlikely someone will include it in the search string.


    "The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castles in the air, from air, creating by exertion of the imagination." - Fred Brooks
    Thursday, October 06, 2011 10:08 AM
  • Also,

           StrComp(TextBox4.Text, xlsh.Cells(M, 5), vbTextCompare)

    make sure that the text is being compared to the cells text and not the cell (range) itself

    perhaps....

           StrComp(TextBox4.Text, xlsh.Cells(M, 5).value, vbTextCompare)


    "The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castles in the air, from air, creating by exertion of the imagination." - Fred Brooks
    Thursday, October 06, 2011 10:19 AM