GNT sans publicité, site mobile, fonctionnalitées exclusives...

Sélection de feuille selon la saison

Le
Michel.Girard
Bonsoir
J'essaie de créer une proc qui selectionne une feuille différente chaque
saison, elle plante sauf en hiver
Pourriez-vous me proposer une syntaxe plus évidente ;-)
Merci beaucoup
Michel


'test sur les saisons
'Hiver 21/12
If Month(Date) >= 1 And Day(Date) >= 1 And _
Month(Date) < 4 And Day(Date) < 20 Then
Application.ScreenUpdating = False
Sheets("Hiver").Select
End If
'Printemps 20/03
If Month(Date) > 2 And Day(Date) > 19 And _
Month(Date) < 7 And Day(Date) < 21 Then
'Application.ScreenUpdating = False
Sheets("Printemps").Select
End If
'Eté 21/06
If Month(Date) >= 6 And Day(Date) >= 21 And _
Month(Date) < 10 And Day(Date) < 23 Then
Application.ScreenUpdating = False
Sheets("Ete").Select
End If
'Automne 22/09
If Month(Date) >= 9 And Day(Date) >= 22 And _
Month(Date) <= 12 And Day(Date) < 22 Then
Application.ScreenUpdating = False
Sheets("Automne").Select
End If
'Hiver 21/12
If Month(Date) >= 12 And Day(Date) >= 21 And _
Month(Date) <= 12 And Day(Date) <= 31 Then
Application.ScreenUpdating = False
Sheets("Hiver").Select
End If
Lire les 2 réponses

Vidéos High-Tech et Jeu Vidéo
Téléchargements
Vos réponses
Gagnez chaque mois un abonnement Premium avec GNT : Inscrivez-vous !
Trier par : date / pertinence
FxM
Le #1958315
Bonsoir,

Limites sont à vérifier (< ou <=)

Public Function test(dat)
Select Case dat
Case Is < DateSerial(Year(dat), 3, 20)
test = "hiver"
Case Is < DateSerial(Year(dat), 6, 21)
test = "Printemps"
Case Is < DateSerial(Year(dat), 9, 22)
test = "Ete"
Case Is < DateSerial(Year(dat), 12, 21)
test = "Automne"
Case Else
test = "Hiver2"
End Select
End Function


Sub testetetetete()
arr = Array(DateSerial(2005, 1, 1), _
DateSerial(2005, 3, 19), _
DateSerial(2005, 3, 20), _
DateSerial(2005, 3, 21), _
DateSerial(2005, 6, 20), _
DateSerial(2005, 6, 21), _
DateSerial(2005, 6, 22), _
DateSerial(2005, 9, 21), _
DateSerial(2005, 9, 22), _
DateSerial(2005, 9, 23), _
DateSerial(2005, 12, 11), _
DateSerial(2005, 12, 12), _
DateSerial(2005, 12, 13), _
DateSerial(2005, 12, 31))

For Each vale In arr
lig = Range("A65536").End(xlUp).Row + 1
Range("A" & lig) = vale
Range("B" & lig) = test(vale)
Next vale
End Sub

@+
FxM


Bonsoir
J'essaie de créer une proc qui selectionne une feuille différente chaque
saison, elle plante sauf en hiver
Pourriez-vous me proposer une syntaxe plus évidente ;-)
Merci beaucoup
Michel


'test sur les saisons
'Hiver 21/12
If Month(Date) >= 1 And Day(Date) >= 1 And _
Month(Date) < 4 And Day(Date) < 20 Then
Application.ScreenUpdating = False
Sheets("Hiver").Select
End If
'Printemps 20/03
If Month(Date) > 2 And Day(Date) > 19 And _
Month(Date) < 7 And Day(Date) < 21 Then
'Application.ScreenUpdating = False
Sheets("Printemps").Select
End If
'Eté 21/06
If Month(Date) >= 6 And Day(Date) >= 21 And _
Month(Date) < 10 And Day(Date) < 23 Then
Application.ScreenUpdating = False
Sheets("Ete").Select
End If
'Automne 22/09
If Month(Date) >= 9 And Day(Date) >= 22 And _
Month(Date) <= 12 And Day(Date) < 22 Then
Application.ScreenUpdating = False
Sheets("Automne").Select
End If
'Hiver 21/12
If Month(Date) >= 12 And Day(Date) >= 21 And _
Month(Date) <= 12 And Day(Date) <= 31 Then
Application.ScreenUpdating = False
Sheets("Hiver").Select
End If






Michel.Girard
Le #1960064
Merci beaucoup François
Michel

"FxM" %23%
Bonsoir,

Limites sont à vérifier (< ou <=)

Public Function test(dat)
Select Case dat
Case Is < DateSerial(Year(dat), 3, 20)
test = "hiver"
Case Is < DateSerial(Year(dat), 6, 21)
test = "Printemps"
Case Is < DateSerial(Year(dat), 9, 22)
test = "Ete"
Case Is < DateSerial(Year(dat), 12, 21)
test = "Automne"
Case Else
test = "Hiver2"
End Select
End Function


Sub testetetetete()
arr = Array(DateSerial(2005, 1, 1), _
DateSerial(2005, 3, 19), _
DateSerial(2005, 3, 20), _
DateSerial(2005, 3, 21), _
DateSerial(2005, 6, 20), _
DateSerial(2005, 6, 21), _
DateSerial(2005, 6, 22), _
DateSerial(2005, 9, 21), _
DateSerial(2005, 9, 22), _
DateSerial(2005, 9, 23), _
DateSerial(2005, 12, 11), _
DateSerial(2005, 12, 12), _
DateSerial(2005, 12, 13), _
DateSerial(2005, 12, 31))

For Each vale In arr
lig = Range("A65536").End(xlUp).Row + 1
Range("A" & lig) = vale
Range("B" & lig) = test(vale)
Next vale
End Sub

@+
FxM


Bonsoir
J'essaie de créer une proc qui selectionne une feuille différente chaque
saison, elle plante sauf en hiver
Pourriez-vous me proposer une syntaxe plus évidente ;-)
Merci beaucoup
Michel


'test sur les saisons
'Hiver 21/12
If Month(Date) >= 1 And Day(Date) >= 1 And _
Month(Date) < 4 And Day(Date) < 20 Then
Application.ScreenUpdating = False
Sheets("Hiver").Select
End If
'Printemps 20/03
If Month(Date) > 2 And Day(Date) > 19 And _
Month(Date) < 7 And Day(Date) < 21 Then
'Application.ScreenUpdating = False
Sheets("Printemps").Select
End If
'Eté 21/06
If Month(Date) >= 6 And Day(Date) >= 21 And _
Month(Date) < 10 And Day(Date) < 23 Then
Application.ScreenUpdating = False
Sheets("Ete").Select
End If
'Automne 22/09
If Month(Date) >= 9 And Day(Date) >= 22 And _
Month(Date) <= 12 And Day(Date) < 22 Then
Application.ScreenUpdating = False
Sheets("Automne").Select
End If
'Hiver 21/12
If Month(Date) >= 12 And Day(Date) >= 21 And _
Month(Date) <= 12 And Day(Date) <= 31 Then
Application.ScreenUpdating = False
Sheets("Hiver").Select
End If







Publicité
Suivre les réponses
Poster une réponse
Anonyme