ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   IF (xORy) AND (xORy)...? (https://www.excelbanter.com/excel-programming/375754-if-xory-xory.html)

markx

IF (xORy) AND (xORy)...?
 
Hi guys,

I'm using the following code in order to hide the rows where both column A
and B are with yellow background:
---------------
Sub RowHide()

Application.ScreenUpdating = False

Dim iRow As Long
Dim maxRows As Long

maxRows = Range("$A$1").CurrentRegion.Rows.Count
With Worksheets(ActiveSheet.Name)
For iRow = 1 To maxRows
If .Cells(iRow, 1).Interior.ColorIndex = 6 _
And .Cells(iRow, 2).Interior.ColorIndex = 6 _
Then
.Rows(iRow).Hidden = True
End If
Next iRow
End With

Application.ScreenUpdating = True

End Sub
---------------

I would like however to expand this code a bit and add, somewhere/somehow,
an additional condition:

Here is some pseudo-code I'm trying to implement:
If . (Cells(iRow, 1).Interior.ColorIndex = 6 OR
Cells(iRow, 1).Value = "")
And . (Cells(iRow, 2).Interior.ColorIndex = 6 _ OR
Cells(iRow, 2).Value = "")
so that the rows where one of the cells (column 1 or 2) is blank are also
hidden...

Furthermore, maybe you know the way to simplify the code (or to generalize
it so that it'll still stay as it is, even if I expand the analysis from 2
columns to 100 :-))?

Thanks a lot for any hints on this,
Regards,
Mark



Tom Ogilvy

IF (xORy) AND (xORy)...?
 
If (.Cells(iRow, 1).Interior.ColorIndex = 6 OR _
.Cells(iRow, 1).Value = "") And _
(.Cells(iRow, 2).Interior.ColorIndex = 6 OR _
.Cells(iRow, 2).Value = "") Then

--
Regards,
Tom Ogilvy





"markx" wrote:

Hi guys,

I'm using the following code in order to hide the rows where both column A
and B are with yellow background:
---------------
Sub RowHide()

Application.ScreenUpdating = False

Dim iRow As Long
Dim maxRows As Long

maxRows = Range("$A$1").CurrentRegion.Rows.Count
With Worksheets(ActiveSheet.Name)
For iRow = 1 To maxRows
If .Cells(iRow, 1).Interior.ColorIndex = 6 _
And .Cells(iRow, 2).Interior.ColorIndex = 6 _
Then
.Rows(iRow).Hidden = True
End If
Next iRow
End With

Application.ScreenUpdating = True

End Sub
---------------

I would like however to expand this code a bit and add, somewhere/somehow,
an additional condition:

Here is some pseudo-code I'm trying to implement:
If . (Cells(iRow, 1).Interior.ColorIndex = 6 OR
Cells(iRow, 1).Value = "")
And . (Cells(iRow, 2).Interior.ColorIndex = 6 _ OR
Cells(iRow, 2).Value = "")
so that the rows where one of the cells (column 1 or 2) is blank are also
hidden...

Furthermore, maybe you know the way to simplify the code (or to generalize
it so that it'll still stay as it is, even if I expand the analysis from 2
columns to 100 :-))?

Thanks a lot for any hints on this,
Regards,
Mark





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

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