convert the if statements to OR conditions

nynamyna

New Member
Joined
Jul 12, 2009
Messages
34
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 all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,752
Members
448,989
Latest member
mariah3

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top