Consulting

Results 1 to 9 of 9

Thread: Solved: If make confusing..

  1. #1

    Question Solved: If make confusing..

    There are tow choice the first one works if the value in texbox1 <> the value in the column A and the caption in lable1 = the vlaue in column B
    the second must works if the textbox1= the value in column A and lable1 = the vlaue in column B

    but the problem is the first choice work in both case .. how t ofix this problem

    [VBA]
    Dim rs As Range
    'the first choice
    With Sheets(1)
    For Each rs In Sheets(1).Range("a1", .Range("a" & Rows.Count).End(xlUp))
    If rs.Value <> TextBox1.Text And rs.Offset(0, 1).Value = Label1.Caption Then
    MsgBox "No"
    Exit Sub
    End If
    Next rs
    End With
    'the second choice
    MsgBox "Yes"
    [/VBA]

  2. #2
    VBAX Tutor gnod's Avatar
    Joined
    Apr 2006
    Posts
    257
    Location
    your second choice is not in the if condition.
    try this

    [VBA]
    If rs.Value <> TextBox1.Text And rs.Offset(0, 1).Value = Label1.Caption Then
    MsgBox "No"
    Else
    'the second choice
    MsgBox "Yes"
    End If
    [/VBA]

  3. #3
    It works only for one row and it give me yes then no
    [VBA]
    Dim rs As Range
    'the first choice
    With Sheets(1)
    For Each rs In Sheets(1).Range("a1", .Range("a" & Rows.Count).End(xlUp))
    If rs.Value <> TextBox1.Text And rs.Offset(0, 1).Value = Label1.Caption Then
    MsgBox "No"
    Exit Sub


    Else
    MsgBox "Yes"
    End If

    Next rs
    End With
    [/VBA]

  4. #4
    VBAX Tutor gnod's Avatar
    Joined
    Apr 2006
    Posts
    257
    Location
    No, it works from the 2 rows, from row 1 up to the last row.
    i add the row # for your reference.

    [VBA]
    Dim rs As Range
    'the first choice
    With Sheets(1)
    For Each rs In Sheets(1).Range("a1", .Range("a" & Rows.Count).End(xlUp))
    If rs.Value <> TextBox1.Text And rs.Offset(0, 1).Value = Label1.Caption Then
    MsgBox "No" & Chr(13) & "Row " & rs.Row
    'Exit Sub


    Else
    MsgBox "Yes" & Chr(13) & "Row " & rs.Row
    End If

    Next rs
    End With
    End Sub
    [/VBA]

  5. #5
    Same problem . I want the first choice releases only if there is not any value equal the value in the textbox so if there is at least one value in the column 1 it will release the second choice.

  6. #6
    VBAX Tutor gnod's Avatar
    Joined
    Apr 2006
    Posts
    257
    Location
    i'm confuse..

    1st choice will be release if the value is not equal to the textbox AND the value in column B is equal to the label.caption

    2nd choice will be release if the value is equal to the textbox AND the value in column B is equal to the label.caption

    the code below is satisfy with the above statement..
    [VBA]
    Dim rs As Range
    'the first choice
    With Sheets(1)
    For Each rs In Sheets(1).Range("a1", .Range("a" & Rows.Count).End(xlUp))
    If rs.Value <> TextBox1.Text And rs.Offset(0, 1).Value = Label1.Caption Then
    MsgBox "1st choice - No" & Chr(13) & rs.Value & " <> " & TextBox1.Text & Chr(13) & "Row " & rs.Row
    'Exit Sub


    Else
    MsgBox "2nd choice - Yes" & Chr(13) & rs.Value & " <> " & TextBox1.Text & Chr(13) & "Row " & rs.Row
    End If

    Next rs
    End With
    [/VBA]

  7. #7

  8. #8
    VBAX Tutor gnod's Avatar
    Joined
    Apr 2006
    Posts
    257
    Location
    does it solve your problem? pls mark it SOLVED under Thread Tools..

  9. #9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •