mathsbeauty
Board Regular
- Joined
- Apr 23, 2011
- Messages
- 89
Hello! I am new here. I have two macros.
1. This Macro Hides all columns whose first entry is "N" and shows all columns whose first entry is "Y".
2. The another Macro unhides all columns i.e. entire data is shown.
I need to modify these two macros to the following (or create new ones)
1. The first macro should hide all columns whose first entry is "N" and shows all columns whose first entry is Y and hides those rows which contains "NO" in this column (whose first entry is Y).
2. This macro should unhide all rows and columns i.e. entire data is shown.
The Macro code is:
Option Explicit
Sub hideCols()
Dim cl As Range
Dim rng As Range
With Worksheets(1)
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlToRight))
For Each cl In rng
If cl.Text = "N" Then cl.EntireColumn.Hidden = True
Next cl
End With
End Sub
Sub showCols()
Dim col As Long
Dim cnt As Long
cnt = Worksheets(1).UsedRange.Columns.Count
For col = 1 To cnt
If Columns(col).EntireColumn.Hidden = True Then Columns(col).EntireColumn.Hidden = False
Next
End Sub
I hope to get some help from experts. I will be really thankful if I get some help.
1. This Macro Hides all columns whose first entry is "N" and shows all columns whose first entry is "Y".
2. The another Macro unhides all columns i.e. entire data is shown.
I need to modify these two macros to the following (or create new ones)
1. The first macro should hide all columns whose first entry is "N" and shows all columns whose first entry is Y and hides those rows which contains "NO" in this column (whose first entry is Y).
2. This macro should unhide all rows and columns i.e. entire data is shown.
The Macro code is:
Option Explicit
Sub hideCols()
Dim cl As Range
Dim rng As Range
With Worksheets(1)
Set rng = .Range(.Cells(1, 1), .Cells(1, 1).End(xlToRight))
For Each cl In rng
If cl.Text = "N" Then cl.EntireColumn.Hidden = True
Next cl
End With
End Sub
Sub showCols()
Dim col As Long
Dim cnt As Long
cnt = Worksheets(1).UsedRange.Columns.Count
For col = 1 To cnt
If Columns(col).EntireColumn.Hidden = True Then Columns(col).EntireColumn.Hidden = False
Next
End Sub
I hope to get some help from experts. I will be really thankful if I get some help.