AW: Spalten ausblenden nach ausgewählten Zellen
24.01.2020 16:15:45
Werner
Hallo,
meinst du so:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim i As Long, raSpalte As Range
Select Case Target.Row
Case 1
If UCase(Target) = "WET" Then
Cancel = True
For i = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
If UCase(Cells(1, i)) = "WET" Then
If raSpalte Is Nothing Then
Set raSpalte = Cells(1, i)
Else
Set raSpalte = Union(raSpalte, Cells(1, i))
End If
End If
Next i
raSpalte.EntireColumn.Hidden = True
Set raSpalte = Nothing
End If
Case 2
If UCase(Target) = "STYRAX" Then
Cancel = True
For i = 1 To Cells(2, Columns.Count).End(xlToLeft).Column
If UCase(Cells(2, i)) = "STYRAX" Then
If raSpalte Is Nothing Then
Set raSpalte = Cells(2, i)
Else
Set raSpalte = Union(raSpalte, Cells(2, i))
End If
End If
Next i
raSpalte.EntireColumn.Hidden = True
Set raSpalte = Nothing
End If
Case 3
If UCase(Target) = "A31" Then
Cancel = True
For i = 1 To Cells(3, Columns.Count).End(xlToLeft).Column
If UCase(Cells(3, i)) = "A31" Then
If raSpalte Is Nothing Then
Set raSpalte = Cells(3, i)
Else
Set raSpalte = Union(raSpalte, Cells(3, i))
End If
End If
Next i
raSpalte.EntireColumn.Hidden = True
Set raSpalte = Nothing
End If
Case Else
End Select
End Sub
Das Makro gehört ins Codemodul des Tabellenblattes, auf der es sich auswirken soll.
Rechtsklick auf den Tabellenblattreiter - Code anzeigen - Code rechts ins Codefenster kopieren.
Das Makro startet automatisch bei Doppelklick auf die entsprechende Zelle in Zeile 1, 2 oder 3
Gruß Werner