Problème dans les conditions pour une textbox avec excel et VBA 6

Résolu
fireup11 Messages postés 2 Date d'inscription mardi 3 février 2009 Statut Membre Dernière intervention 3 février 2009 - 3 févr. 2009 à 17:55
fireup11 Messages postés 2 Date d'inscription mardi 3 février 2009 Statut Membre Dernière intervention 3 février 2009 - 3 févr. 2009 à 22:19
Bonjour à tous,

Je développe un programme présentement avec aucune base mais je me débrouille quand même et j'aimerai savoir si quelqu'un peut m'aider à simplifier ce code qui est astronomiquement trop grand et j'en suis certain doit se simplifier énormément: J'ai une texte box dans une feuille ("Feuil1") ou l'on doit entrer le nombre de jour soit 1 , 2 , 3 etc. lorsque je presse sur le bouton de commande il doit aller écrire sur une autre feuille ("paramètre") dans une colonne comme suit: 1h00, 2h00 , 3h00 ,4h00; bref le nombre d'heure dans une journée multiplié par le nombre de jour entré dans la textbox. Voici un exemple de mon code pour quelqu'un qui aurait entré "2" dans le textbox:
_______________________________________________________________________________
If TextBox3.Value = "2" Then
Sheets("paramètre").Range("B4").Value = "01h00"
Sheets("paramètre").Range("B5").Value = "02h00"
Sheets("paramètre").Range("B6").Value = "03h00"
Sheets("paramètre").Range("B7").Value = "04h00"
Sheets("paramètre").Range("B8").Value = "05h00"
Sheets("paramètre").Range("B9").Value = "06h00"
Sheets("paramètre").Range("B10").Value = "07h00"
Sheets("paramètre").Range("B11").Value = "08h00"
Sheets("paramètre").Range("B12").Value = "09h00"
Sheets("paramètre").Range("B13").Value = "10h00"
Sheets("paramètre").Range("B14").Value = "11h00"
Sheets("paramètre").Range("B15").Value = "12h00"
Sheets("paramètre").Range("B16").Value = "13h00"
Sheets("paramètre").Range("B17").Value = "14h00"
Sheets("paramètre").Range("B18").Value = "15h00"
Sheets("paramètre").Range("B19").Value = "16h00"
Sheets("paramètre").Range("B20").Value = "17h00"
Sheets("paramètre").Range("B21").Value = "18h00"
Sheets("paramètre").Range("B22").Value = "19h00"
Sheets("paramètre").Range("B23").Value = "20h00"
Sheets("paramètre").Range("B24").Value = "21h00"
Sheets("paramètre").Range("B25").Value = "22h00"
Sheets("paramètre").Range("B26").Value = "23h00"
Sheets("paramètre").Range("B27").Value = "24h00"
Sheets("paramètre").Range("B28").Value = "01h00"
Sheets("paramètre").Range("B29").Value = "02h00"
Sheets("paramètre").Range("B30").Value = "03h00"
Sheets("paramètre").Range("B31").Value = "04h00"
Sheets("paramètre").Range("B32").Value = "05h00"
Sheets("paramètre").Range("B33").Value = "06h00"
Sheets("paramètre").Range("B34").Value = "07h00"
Sheets("paramètre").Range("B35").Value = "08h00"
Sheets("paramètre").Range("B36").Value = "09h00"
Sheets("paramètre").Range("B37").Value = "10h00"
Sheets("paramètre").Range("B38").Value = "11h00"
Sheets("paramètre").Range("B39").Value = "12h00"
Sheets("paramètre").Range("B40").Value = "13h00"
Sheets("paramètre").Range("B41").Value = "14h00"
Sheets("paramètre").Range("B42").Value = "15h00"
Sheets("paramètre").Range("B43").Value = "16h00"
Sheets("paramètre").Range("B44").Value = "17h00"
Sheets("paramètre").Range("B45").Value = "18h00"
Sheets("paramètre").Range("B46").Value = "19h00"
Sheets("paramètre").Range("B47").Value = "20h00"
Sheets("paramètre").Range("B48").Value = "21h00"
Sheets("paramètre").Range("B49").Value = "22h00"
Sheets("paramètre").Range("B50").Value = "23h00"
Sheets("paramètre").Range("B51").Value = "24h00"
End If
_______________________________________________________________________________
Vous comprendrez que j'ai rapidement atteint le nombre maximal de caractère par bouton de commande étant donné que je l'ai créé pour plusieurs jour

Je vous demande cordialement votre aide

Merci d'avance
David

3 réponses

jmf0 Messages postés 1566 Date d'inscription mardi 26 décembre 2000 Statut Membre Dernière intervention 5 avril 2013 8
3 févr. 2009 à 20:28
Bonjour,

ne te semble-til pas que :
tant tes cellules que tes heures avançant de une unité, une bouble for ...to...Next ferait parfaitement l'affaire, tant pour tes ranges que pour tes heures (en utilisant dateadd pour incrémenter tes heures) ... ?
A toi de t'y mettre (c'est trop simple !)
3
Mikaels35 Messages postés 146 Date d'inscription dimanche 23 janvier 2005 Statut Membre Dernière intervention 17 novembre 2009 2
3 févr. 2009 à 20:30
Tu peux partir sur cette base

Dim i as Integer, a As Integer

If TextBox3.Value = "2" Then
    For i = 4 To 51
        a = IIf(i < 28, 3, 27)
       Sheets("paramètre").Range("B" & CStr(i)).Value = Format(CStr(i - a), "00") & "h00"
    Next i
End If

Ensuite tu adaptes à tes besoins pour les autres valeurs de la TextBox.

@+
3
fireup11 Messages postés 2 Date d'inscription mardi 3 février 2009 Statut Membre Dernière intervention 3 février 2009
3 févr. 2009 à 22:19
Tres bien merci beaucoup je vais m'y mettre avec vos réponses!!
0
Rejoignez-nous