manekankit
Board Regular
- Joined
- Feb 1, 2019
- Messages
- 71
- Office Version
- 365
- Platform
- Windows
I am having a macro to hide/unhide row based on cell value. I.e. if value in column A in respective cell is zero, then the row should be hidden and if the value in the column A in respective cell is not equal to zero, then the row should be visible. (E.g. if A5=0, row 5 should be hidden (if not hidden already), if A6<>0, it should be visible (if not visible already).
I am using below code which is working fine on each sheet.
Macro 1
Now I want to run this macro on all the sheets together at once. For that I am using below code, but the code is not running on all the sheets but only on one active sheet.
Macro 2
Need help to identify why the Macro 2 is not running on all the sheets. I am using office 365 64bit.
Also in Macro 2 I want to add one more condition. Macro should run only on those sheets where value in cell A1 of respective sheet is equal to “RowHide”.
I am using below code which is working fine on each sheet.
Macro 1
VBA Code:
Sub RowHide()
Dim A As Range
Set MX = ActiveSheet.Range("A2:A500")
For Each A In MX
If A.Value = "0" And A.Rows.Hidden = False Then
A.EntireRow.Hidden = True
End If
If A.Value <> "0" And A.Rows.Hidden = True Then
A.EntireRow.Hidden = False
End If
Next A
End Sub
Now I want to run this macro on all the sheets together at once. For that I am using below code, but the code is not running on all the sheets but only on one active sheet.
Macro 2
VBA Code:
Sub RowHideAllSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
Dim A As Range
Set MX = ActiveSheet.Range("A2:A500")
For Each A In MX
If A.Value = "0" And A.Rows.Hidden = False Then
A.EntireRow.Hidden = True
End If
If A.Value <> "0" And A.Rows.Hidden = True Then
A.EntireRow.Hidden = False
End If
Next A
Next ws
End Sub
Need help to identify why the Macro 2 is not running on all the sheets. I am using office 365 64bit.
Also in Macro 2 I want to add one more condition. Macro should run only on those sheets where value in cell A1 of respective sheet is equal to “RowHide”.
Last edited by a moderator: