ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to use 2 conditions in if (https://www.excelbanter.com/excel-programming/368606-how-use-2-conditions-if.html)

Sergei D

how to use 2 conditions in if
 
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

--
Sergei D

Bob Phillips

how to use 2 conditions in if
 
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)

"Sergei D" wrote in message
...
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

--
Sergei D




Jim Thomlinson

how to use 2 conditions in if
 
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
--
HTH...

Jim Thomlinson


"Sergei D" wrote:

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

--
Sergei D


Sergei D

how to use 2 conditions in if
 
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!
--
Sergei D


"Jim Thomlinson" wrote:

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
--
HTH...

Jim Thomlinson


"Sergei D" wrote:

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

--
Sergei D



All times are GMT +1. The time now is 11:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com