-
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]
-
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]
-
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]
-
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]
-
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.
-
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]
-
-
does it solve your problem? pls mark it SOLVED under Thread Tools..
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules