Hi everyone,
I have a sheet with two blocks of data. On both blocks, I want to hide a different number of rows, using the following code. The thing is that VBA says I can't have two of the same. Is there a way to have one (or more) macro(s) have multiple Worksheet_SelectionChange(ByVal Target As Range), with each one looking at one of the two blocks? So I fill my block of data, change the number of rows I want to change in that block, and move on to the next block, etc. The alternative is to have a regular macro in a module and add it to a button, but I'm exploring this option first. Any help is greatly appreciated!
Cheers, Elmacay
I have a sheet with two blocks of data. On both blocks, I want to hide a different number of rows, using the following code. The thing is that VBA says I can't have two of the same. Is there a way to have one (or more) macro(s) have multiple Worksheet_SelectionChange(ByVal Target As Range), with each one looking at one of the two blocks? So I fill my block of data, change the number of rows I want to change in that block, and move on to the next block, etc. The alternative is to have a regular macro in a module and add it to a button, but I'm exploring this option first. Any help is greatly appreciated!
Cheers, Elmacay
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim w As Worksheet
If Target.Address = "$N$52" Then
If IsNumeric(Target.Value) Then
If Target.Value > -1 And Target.Value < 17 Then
Set w = ActiveWorkbook.Sheets("Invoerblad woninggegevens")
w.Range("A54:A69").EntireRow.Hidden = False
w.Range("A" & Target.Value + 54 & ":A69").EntireRow.Hidden = True
End If
End If
End If
End Sub
________________________________________________________________________
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim w As Worksheet
If Target.Address = "$N$102" Then
If IsNumeric(Target.Value) Then
If Target.Value > -1 And Target.Value < 17 Then
Set w = ActiveWorkbook.Sheets("Invoerblad woninggegevens")
w.Range("A104:A119").EntireRow.Hidden = False
w.Range("A" & Target.Value + 104 & ":A119").EntireRow.Hidden = True
End If
End If
End If
End Sub