# convert the if statements to OR conditions

#### nynamyna

##### New Member
Hello everybody,

I have the following if conditions which I have to convert into OR statements in a simple way. That is, if either one of this condition is true then the variable count should be updated (count =count +1)

<!-- BEGIN TEMPLATE: bbcode_code -->
Code:
``````lastrow = Sheets(2).UsedRange.Rows.count
For icell = 2 To lastrow
If (Sheets(2).Range("B" & icell).Value <> Sheets(2).Range("B" & (icell - 1)).Value) Then

If (Sheets(2).Range("P" & icell).Value <> Sheets(2).Range("P" & (icell - 1)).Value) Then

If (Sheets(2).Range("R" & icell).Value <> Sheets(2).Range("R" & (icell - 1)).Value) Then

if (Sheets(2).Range("T" & icell).Value <> Sheets(2).Range("T" & (icell - 1)).Value) Then

If (Sheets(2).Range("U" & icell).Value <> Sheets(2).Range("U" & (icell - 1)).Value) Then

If (Sheets(2).Range("V" & icell).Value <> Sheets(2).Range("V" & (icell - 1)).Value) Then

count = count +1

Next icell``````

Thanks,
Vijay

### Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

#### MrKowz

##### Well-known Member
Something like this?

Code:
``````With Sheets(2)
lastrow = .UsedRange.Rows.Count
For icell = 2 To lastrow
If (.Range("B" & icell).Value <> .Range("B" & (icell - 1)).Value) Or _
(.Range("P" & icell).Value <> .Range("P" & (icell - 1)).Value) Or _
(.Range("R" & icell).Value <> .Range("R" & (icell - 1)).Value) Or _
(.Range("T" & icell).Value <> .Range("T" & (icell - 1)).Value) Or _
(.Range("U" & icell).Value <> .Range("U" & (icell - 1)).Value) Or _
(.Range("V" & icell).Value <> .Range("V" & (icell - 1)).Value) Then

Count = Count + 1
End If
Next icell
End With``````

#### nynamyna

##### New Member
yes...is this the final code ?

#### MrKowz

##### Well-known Member
yes...is this the final code ?

It is the final code based on what you supplied. I also cleaned it up by adding a With statement.

#### nynamyna

##### New Member
got it..thanks..this is what I want

Replies
0
Views
725
Replies
8
Views
326
Replies
15
Views
395
Replies
0
Views
191
Replies
0
Views
270

1,191,120
Messages
5,984,762
Members
439,909
Latest member
daigoku

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back