Simple If else Loop with hide row

 sam -

I'm making a spreadsheet where in I want to hide those rows when the cell in column d is not equal to the value in cell b1.

I just do not know what the statements for the macro should be, since i do not know anything in VB but I think here is what I want to happen..

*b1 is a selection of categories(variable)
*range of list is A3:L450
*column a is the list of items
*column c indicates what is the category of the item

go to c3

if current cell=b1 then go to the next row(same column)
else hide the current row then go to the next row(same column)

repeat this if statements while current cell is <=c450

3 replies

Registration date
Saturday February 16, 2008
Last seen
October 17, 2008
here is a solution in a kit form. Dare ask if you need more help.

Use a "For Each...Next" loop :
Dim MyCell As Range, MyRange As Range
    Set MyRange = Range("C3:C450")
    For Each MyCell In MyRange
    Next MyCell

The "if" statement would be :
If MyCell.Value <> Range("B1").Value Then
End If

Then, to hide a row, have a look at "Range.EntireRow" and "Range.Hidden" in the help file.

To make your code run faster, think of using "Application.ScreenUpdating" (see help file)

If you want your macro to run automatically when you change the selection in B1, see the help file about the events of a worksheet.
how to write a vba to remove all formula in column B and column C if the cell value in not equal to #N/A.
Thanks in Advance
hi, i am sam i have a question in why B1 i is not equal to B1