View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Loop through column(s) to check values, perform action based on ch

Let's say A1 thru G10 looks like:

0 0 0 0 0 0 0
1 0 0 0 0 0 0
1 1 0 0 1 0 0
0 1 0 0 1 0 0
1 0 1 0 1 0 1
0 1 0 0 1 0 0
1 1 0 0 1 0 0
0 0 0 0 1 0 1
1 0 1 0 0 0 1
1 1 1 0 0 0 0


and we want to hide cols like D & F which are all zeros

Try this:

Sub sistance()
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row - 1
nLastColumn = r.Columns.Count + r.Column - 1
For i = 1 To nLastColumn
hide_it = True
For j = 1 To nLastRow
If Cells(j, i).Value < 0 Then
hide_it = False
End If
Next
If hide_it Then
Columns(i).EntireColumn.Hidden = True
End If
Next
End Sub
--
Gary''s Student - gsnu200753


"ward376" wrote:

I hope someone has something like this worked out - How to loop
through a column and if every cell contains a certain value (i.e.all
zeros), hide or delete the column.

Thanks!
ward376