Hide row if column does"not" contain

  • Thread starter Thread starter GregR
  • Start date Start date
G

GregR

I have a column of PO numbers all containing 9 digits, like 605031101.
The sixth and seventh digits, in the example "11", represents the
month, Nov. I want to hide all rows that do "not" contain 11, 10 or 09,
Nov, Oct and Sep. How? TIA
 
Try this bit of code:

It assumes the cell pointer is on the first cell and the end sell is blank.

The months are hard codes but you could change this with a little form.

Option Explicit
Sub Hiderow()
Dim cur_row As Long
Dim cur_col As Long
cur_row = ActiveCell.Row
cur_col = ActiveCell.Column
While Cells(cur_row, cur_col) <> ""
Select Case Mid(Cells(cur_row, cur_col), 6, 2)
Case 9 To 11
' ok do nothing
Case Else
Rows(cur_row).Hidden = True
End Select
If cur_row = 65536 Then Exit Sub
cur_row = cur_row + 1
Wend
End Sub
 
Back
Top