Hello everyone,
Excuse my ignorance but I found this macro, which works for hidding columns:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("D7).Value = 0 Then
Columns("D").EntireColumn.Hidden = True
Else
Columns("D").EntireColumn.Hidden = False
End If
If Range("H7).Value = 0 Then
Columns("H").EntireColumn.Hidden = True
Else
Columns("H").EntireColumn.Hidden = False
End If
End Sub
But when I try to specify a range "D7:D58" I get a run-time error - D7 to D58 are all numerical values, and if all of them total 0, the column should be hidden. The same I want to apply for a range of of cell values on rows, like A58:K58, which if total 0, the specified row should also be hidden. The latter I have no idea how to do, but I found this:
Sub HideRows()
BeginRow = 1
EndRow = 100
ChkCol = 3
For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value = 0 Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = True
End If
Next RowCnt
End Sub
Which I doubt I can properly adjust but I will try to. Currently, combining them gives me a different error. The two I will then combine with a macro related to Deferred Taxes calculation, it works (not well written, extremely long), but I fail to understand how to add a secondary macro to it.
What am I doing wrong? And is it possible to combine at least the two?
Thank you in advance.
Excuse my ignorance but I found this macro, which works for hidding columns:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("D7).Value = 0 Then
Columns("D").EntireColumn.Hidden = True
Else
Columns("D").EntireColumn.Hidden = False
End If
If Range("H7).Value = 0 Then
Columns("H").EntireColumn.Hidden = True
Else
Columns("H").EntireColumn.Hidden = False
End If
End Sub
But when I try to specify a range "D7:D58" I get a run-time error - D7 to D58 are all numerical values, and if all of them total 0, the column should be hidden. The same I want to apply for a range of of cell values on rows, like A58:K58, which if total 0, the specified row should also be hidden. The latter I have no idea how to do, but I found this:
Sub HideRows()
BeginRow = 1
EndRow = 100
ChkCol = 3
For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value = 0 Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = True
End If
Next RowCnt
End Sub
Which I doubt I can properly adjust but I will try to. Currently, combining them gives me a different error. The two I will then combine with a macro related to Deferred Taxes calculation, it works (not well written, extremely long), but I fail to understand how to add a secondary macro to it.
What am I doing wrong? And is it possible to combine at least the two?
Thank you in advance.