Simple If else Loop with hide row

Closed
Ninong - Sep 25, 2008 at 07:19 AM
 sam - Apr 10, 2010 at 07:37 AM
Hello,

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
Related:

3 responses

Ivan-hoe Posts 433 Registration date Saturday February 16, 2008 Status Member Last seen October 17, 2008 110
Sep 26, 2008 at 02:55 AM
Hello,
here is a solution in a kit form. Dare ask if you need more help.
Ivan

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

The "if" statement would be :
If MyCell.Value <> Range("B1").Value Then
    'instructions
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.
9
Sir,
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
2
hi, i am sam i have a question in vb.net why B1 i is not equal to B1
2