Hi Naveen
I have seen that Mr. Khaleel has answered your query in a very simple way.
Nevertheless I also worked on your problem and i also have devised a small VBA.
It is a bit complicated but still u can have a look at it also.
U will have to copy the entire macro in the Sheet module (Not n the Work book macro )
The macro uses the property of "Change" in the sheet . As soon there is any change in Sheet data , it will execute itself . Effectively meaning every time u press ENTER or Update anything in the sheet , The Macro will run.
The macro will work as follows :
If u type anything in Cell A1 , it will hide the rows and columns as specified in macro Hide_Row_ Col .
If u delete the contents from A1 or the contents of A1 is blank it will unhide the cells by using macro unhide_Row_Col.
The macro is :
Public Cell_Change, current_cell
Sub Worksheet_Change(ByVal Target As Range)
Dim rg As Range
current_cell = ActiveCell.Address
Set rg = Intersect(Cells(1, 1), Target)
If rg Is Nothing Then
UnHideRow_column ' Check if there is any data in cells A1
Else
If Cells(1, 1).Value = "" Then ' Check if the Cell A1 is blank
UnHideRow_column
Else
hide_row_Col
End If
End If
End Sub
Sub UnHideRow_column()
If Cells(1, 1).Value = "" Then
Rows("6:8").Select ' These rows will hide , you can change these as u like
Selection.EntireRow.Hidden = False
Columns("C:D").Select ' These col will hide u can change
Range("C5").Activate
Selection.EntireColumn.Hidden = False
Range(current_cell).Activate
Range(current_cell).Select ' This will take u back to the cell where u where 'working
End If
Exit Sub
End Sub
Sub hide_row_Col()
Rows("6:8").Select
Selection.EntireRow.Hidden = True
Columns("C:D").Select
Range("C5").Activate
Selection.EntireColumn.Hidden = True
Range(current_cell).Select
End Sub
Mr. Khaleel please help me in reducing the number of If Statement in this macro
Regards
Abhishek