PDA

View Full Version : Solved: If make confusing..



Nader
03-20-2008, 08:13 AM
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


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"

gnod
03-20-2008, 08:30 AM
your second choice is not in the if condition.
try this


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

Nader
03-20-2008, 08:38 AM
It works only for one row and it give me yes then no

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

gnod
03-20-2008, 09:08 AM
No, it works from the 2 rows, from row 1 up to the last row.
i add the row # for your reference.


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

Nader
03-20-2008, 09:19 AM
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.

gnod
03-20-2008, 09:38 AM
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..

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

Nader
03-20-2008, 12:04 PM
Thank you

gnod
03-20-2008, 07:54 PM
does it solve your problem? pls mark it SOLVED under Thread Tools..

Nader
03-21-2008, 07:33 AM
Than kyou