how to use 2 conditions in if

G

Guest

This is a follow up on my last question. I am sorry I did not formulate my
question right. In my example I have only one range (“a8:a30â€). I need it,
after it matches the cell = 1122 in column A, to go to column B and meet
another condition. Basically, I need it to match column A with column B and
then I want it to evaluate IF.
Dim cell As Range
Dim str As String
For Each cell In Range("a8:a30")
If cell = 1122 Then

cell.Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
ElseIf Not IsEmpty(cell.Value) Then
cell.Select
With Selection.Interior
.ColorIndex = 5
.Pattern = xlSolid
End With
Else: Range("a33").Select
ActiveCell.FormulaR1C1 = "end of transactions"
End If
Next cell
End Sub
 
B

Bob Phillips

If cell = 1122 Then
If cell.Value = cell.Offset(0,1).Value Then
....
End If

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
G

Guest

Y have a range object cell which you are using to traverse the range A8:A30.
If I understand you correctly you want to check the value of cell and cell
offset one column to the right (Column B)

if cell.value = 1122 and cell.offset(0,1).value = 2211 then

end if
 
G

Guest

Thank you so much. I can not believe this is so easy... I spent a lot of time
trying to do the same with many lines of code which did not work. This works
perfectly. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top