1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim WSname As String
Dim WScheck As Worksheet
Dim WScheckname As String
If Not Intersect(Target, Range("B2:B22")) Is Nothing Then
WSname = Range("B" & Target.Row)'faudrait peut-être mettre ici Activecell car si je souhaite double-cliquer sur n'importe qu'elle cellule situé entre B2 et B22, il me faut aller à l'onglet correspondant ou le créer!
On Error Resume Next
Set WScheck = Sheets(WSname)
If WScheck Is Nothing Then 'Doesn't exist so create it
Sheets("Example").Copy Before:=Sheets(Worksheets.Count)
ActiveSheet.Name = WSname
ActiveSheet.Visible = True
Set WScheck = Nothing
On Error GoTo 0
Else 'Does exist so activate it
Sheets(WSname).Activate
Set WScheck = Nothing
On Error GoTo 0
End If
End If
End Sub |