Hi, the following code loops through a number of columns to compare the cell value in row 30 to the values below down to last row. If all of the values are the same it will insert the word HIDE in row 27 for each column. I need help to modify the code so that blank cells are ignored in the columns and only cells that have a value are considered. Currently, if I insert a blank line, the criteria won't be met that all cells will match the top cell. I hope this is clear. Thanks for the help.
VBA Code:
Sub DetailColumHide()
' Macro to populate the row-27 w/ "HIDE" if all categories in the column are the same (excluding accessories)
Worksheets("DETAIL FORM").Select
Dim lr As Long 'last row
Dim cat As Variant 'category
Dim x As Long 'loop counter variable
Dim y As Long 'loop counter variable
Dim hide As Long 'counter for category in column loop
lr = Worksheets("DETAIL FORM").Cells(Rows.Count, 7).End(xlUp).Row - 1 'find last cell used in Col.G (7)
If lr < 30 Then Exit Sub
lr = lr - Range("B2").Value 'subtract "NUMBER OF ACCESS LINES >>" to NOT count accessories
For x = 9 To 27 'Col.I to Col.AA 12/31/19 Steve changed to "9 to 26", and col AA to Z. Reason is col AA should always hide.
cat = ActiveSheet.Cells(30, x)
hide = 0
For y = 31 To lr
If ActiveSheet.Cells(y, x).Value = cat Then hide = hide + 1
Next y
If hide + 30 = lr Then
ActiveSheet.Cells(27, x).Value = "HIDE"
Else
ActiveSheet.Cells(27, x).Value = ""
End If
Next x
End Sub