Hi experts,
So, much like the title of the thread suggest, I have been trying to string together a code that will allow me to hide rows if said rows does not have any cell values in the visible columns of my worksheet.
The idea is that in my dataset I might be interested in only seeing values for a specific week - and as such, all other columns (weeks) will be hidden. More to that end, I also only want to see rows where a value is present within my specified range.
The first piece of the puzzle - namely that of hiding columns based on a specified value - I've managed to solve with the following code:
So far so good!
However, the second part - namely to then further only showcase rows with cell value within the specified range of the code posted above - I simply can't figure out.
At first I looked into the subtotal function of Excel, but that apparently only works on filtered values and hidden rows, not columns.
I then tried to create a volatile public function to count whether any values were present in my specified range to use as a helper - it worked, but it took ages to calculate every time a change was added to the data range. So long in fact that it just isn't an option.
I'm relatively new to VBA and coding in general, so any tips, tricks and suggestions would be greatly appreciated!
Best regards,
Jannick
So, much like the title of the thread suggest, I have been trying to string together a code that will allow me to hide rows if said rows does not have any cell values in the visible columns of my worksheet.
The idea is that in my dataset I might be interested in only seeing values for a specific week - and as such, all other columns (weeks) will be hidden. More to that end, I also only want to see rows where a value is present within my specified range.
The first piece of the puzzle - namely that of hiding columns based on a specified value - I've managed to solve with the following code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cel As Range, Headers As Range
Dim s As String
Set Headers = Range("G1:ABC1")
If Target.Address = "$E$16" Then
s = Target.Value
Application.ScreenUpdating = False
If s = "" Then
Headers.EntireColumn.Hidden = False
Else
For Each cel In Headers
cel.EntireColumn.Hidden = Not cel.Value = s
Next cel
End If
Application.ScreenUpdating = True
End If
End Sub
So far so good!
However, the second part - namely to then further only showcase rows with cell value within the specified range of the code posted above - I simply can't figure out.
At first I looked into the subtotal function of Excel, but that apparently only works on filtered values and hidden rows, not columns.
I then tried to create a volatile public function to count whether any values were present in my specified range to use as a helper - it worked, but it took ages to calculate every time a change was added to the data range. So long in fact that it just isn't an option.
I'm relatively new to VBA and coding in general, so any tips, tricks and suggestions would be greatly appreciated!
Best regards,
Jannick