# having trouble with combining 2 "IF" statements

#### kbishop94

##### Active Member
I have these 2 statements:

Code:
``````For Each Cell In Range(Cells(4, 6), Cells(4, lCol))
If Cell = "a" Then Columns(Cell.Column).Hidden = True Else Columns(Cell.Column).Hidden = False
Next``````

Code:
``````For Each Cell In Range(Cells(5, 6), Cells(5, lCol))
If Cell = "R" Then Columns(Cell.Column).Hidden = True Else Columns(Cell.Column).Hidden = False
Next``````

The first one is to look in row 4 and any cells that have "a" in them then hide that column.
The second is to look in row 5 and any cells that have "R" in them, then hide those columns.

How can I make it so that it is looking at both row 4 for "a" 's, and row 5 for "R" 's and hides all of those columns that meet that criteria?

### Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

#### Fluff

##### MrExcel MVP, Moderator
Code:
``````   For Each Cell In Range(Cells(4, 6), Cells(4, lCol))
Columns(Cell.Column).Hidden = IIf(Cell.Value = "a" And Cell.Offset(1).Value = "R", True, False)
Next``````

#### wideboydixon

##### Well-known Member
Code:
``````For thisCol = 6 To lCol
Columns(thisCol).Hidden = Cells(4, lCol).Value = "a" And Cells(5, lCol).Value = "R"
Next``````

WBD

#### kbishop94

##### Active Member
Perfect! Thanks everyone

#### Fluff

##### MrExcel MVP, Moderator
Glad we could help & thanks for the feedback

Replies
2
Views
50
Replies
2
Views
55
Replies
2
Views
55
Replies
5
Views
85
Replies
8
Views
82