Hello. I am trying to build a code which hides entire rows based on the value of two cells. I put the code and an example to a better understanding of my issue. The code is not working, it is giving me an error.
CODE:
Private Sub Hide_Click()
RowNumber = 1
Do
DoEvents
RowNumber = RowNumber + 1
Rng = Sheets("test").Range("A" & RowNumber & ":" & "B" & RowNumber)
Search = Sheets("test").Range("C1")
If InStr(Rng, Search) >= 1 Then
Sheet2.Rows(RowNumber & ":" & row_number).EntireRow.Hidden = True
End If
Loop Until Rng = ""
MsgBox "Done"
End Sub
EXAMPLE:
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD]Spain[/TD]
[/TR]
[TR]
[TD]Spain[/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Spain[/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Spain[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Spain[/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]France[/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]France[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]France[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]France[/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]France[/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
In sum, I have a button which call the code. The code is supposed to hide all the rows based on the cell C1 (with "spain") and that does not contain the "x" in Column B. In that case hide the row 4 only. Eventually, if i put France in C2, hide the rows 7 and 8. The code i have is far from correct but I am really stuck right now.
Hope someone can help me !
Thanks in advance
CODE:
Private Sub Hide_Click()
RowNumber = 1
Do
DoEvents
RowNumber = RowNumber + 1
Rng = Sheets("test").Range("A" & RowNumber & ":" & "B" & RowNumber)
Search = Sheets("test").Range("C1")
If InStr(Rng, Search) >= 1 Then
Sheet2.Rows(RowNumber & ":" & row_number).EntireRow.Hidden = True
End If
Loop Until Rng = ""
MsgBox "Done"
End Sub
EXAMPLE:
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD]Spain[/TD]
[/TR]
[TR]
[TD]Spain[/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Spain[/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Spain[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Spain[/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]France[/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]France[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]France[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]France[/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]France[/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
In sum, I have a button which call the code. The code is supposed to hide all the rows based on the cell C1 (with "spain") and that does not contain the "x" in Column B. In that case hide the row 4 only. Eventually, if i put France in C2, hide the rows 7 and 8. The code i have is far from correct but I am really stuck right now.
Hope someone can help me !
Thanks in advance