faire une boucle

deeppurple

XLDnaute Nouveau
bonjour le forum,

j'ai un souci pour faire une boucle

dans un formulaire et avec le code ci-desous j'alimente deux feuilles excell (SORTIE1 et SORTIE2)(colonne A à S)et ça marche.


sur ce même formulaire j'ai également 260 textbox numérotés à partir de 1400

je voudrais avec une boucle que dans ma feuille (SORTIE1)

textbox1400 aille en colonneW
textbox1401 aille en colonneX
textbox1402 aille en colonneY, et ainsi de suite

j'ai essayé avec
Code:
[COLOR="Red"]With sheets("SORTIE1")
dim i as integer
i=1400 to 1414
Xls.Cells(i,23)=Me.Controls("Textbox" & i)
next i
end with[/COLOR]
mais ça marche pas

mon code pour rentrer mes données de la colonne A à S

Code:
Private Sub CommandButton2_Click()
Sheets("SORTIE1").Activate
Sheets("SORTIE2").Activate
Dim Xls As Worksheet, Xls1 As Worksheet, lLig As Long
    Set Xls = ThisWorkbook.Worksheets("SORTIE1")
    Set Xls1 = ThisWorkbook.Worksheets("SORTIE2")
    'Recherche la ligne disponible
    lLig = 7

   While Xls.Cells(lLig, 1) <> "" And Xls1.Cells(lLig, 1) <> ""
        lLig = lLig + 1
    Wend
    Xls.Cells(lLig, 1) = CDate(TextBox701.Value)
   Xls.Cells(lLig, 2) = TextBox716.Text
    Xls.Cells(lLig, 3) = TextBox715.Text
   Xls.Cells(lLig, 5) = TextBox713.Text
   Xls.Cells(lLig, 6) = TextBox714.Value
   Xls.Cells(lLig, 7) = ComboBox153.Value
   Xls.Cells(lLig, 8) = TextBox703.Value
    Xls.Cells(lLig, 9) = TextBox704.Value
   Xls.Cells(lLig, 10) = TextBox705.Value
   Xls.Cells(lLig, 11) = TextBox706.Text
   Xls.Cells(lLig, 12) = TextBox1354.Text
   Xls.Cells(lLig, 13) = TextBox1353.Value
   Xls.Cells(lLig, 14) = TextBox709.Value
   Xls.Cells(lLig, 15) = TextBox710.Value
    Xls.Cells(lLig, 16) = TextBox711.Value
   Xls.Cells(lLig, 17) = TextBox712.Value
   Xls1.Cells(lLig, 1) = CDate(TextBox701.Value)
   Xls1.Cells(lLig, 2) = TextBox716.Text
    Xls1.Cells(lLig, 3) = TextBox715.Text
   Xls1.Cells(lLig, 5) = TextBox713.Text
   Xls1.Cells(lLig, 6) = TextBox714.Value
   Xls1.Cells(lLig, 7) = ComboBox153.Value
   Xls1.Cells(lLig, 8) = TextBox703.Value
    Xls1.Cells(lLig, 9) = TextBox704.Value
   Xls1.Cells(lLig, 10) = TextBox705.Value
   Xls1.Cells(lLig, 11) = TextBox706.Text
   Xls1.Cells(lLig, 12) = TextBox1354.Text
   Xls1.Cells(lLig, 13) = TextBox1353.Value
   Xls1.Cells(lLig, 14) = TextBox709.Value
   Xls1.Cells(lLig, 15) = TextBox710.Value
    Xls1.Cells(lLig, 16) = TextBox711.Value
   Xls1.Cells(lLig, 17) = TextBox712.Value
   
End With
End Sub

Pouvez vous me donner un coup de main il faut que je termine ce soir
 

Paritec

XLDnaute Barbatruc
Re : faire une boucle

Bonjour Deep, le forum,
avec I = 1400 to 1414
sheets.Cells(i,23)=Me.Controls("Textbox" & i)
tu veux donc que ta feuille active(ligne 1400, w) soit egal à textbox1400 !!!
et ainsi de suite jusqu'à textbox1414
non, tu veux autre chose mais quoi?
a+
Papou
 

deeppurple

XLDnaute Nouveau
Re : faire une boucle

bonjour papou,

je voudrais quà partir de ma textbox1400, mes données s'inscrivent dans la COLONNE W et ainsi de suite(sachant que tous mes textbox à partir de 1400 se suivent) et en prenant exemple sur mon code dans mon message ci-dessous qui marche dont voici la dernière ligne

Code:
Xls.Cells(lLig, 17) = TextBox712.Value

je voudrais que mes textbox à partir de 1400 aille dans la cellule(lLig,23)et ainsi de suite(mais avec une boucle
 

deeppurple

XLDnaute Nouveau
Re : faire une boucle

j'ai renoté le code qui marche
en rouge c'est la boucle que je veux faire (sachant que mes textbox iront jusque textbox1629)pour la feuille (SORTIE1)


Code:
With Sheets("SORTIE1")
With Sheets("SORTIE2")
Dim Xls As Worksheet, Xls1 As Worksheet, lLig As Long
    Set Xls = ThisWorkbook.Worksheets("SORTIE1")
    Set Xls1 = ThisWorkbook.Worksheets("SORTIE2")
    'Recherche la ligne disponible
    lLig = 7

   While Xls.Cells(lLig, 1) <> "" And Xls1.Cells(lLig, 1) <> ""
        lLig = lLig + 1
    Wend
    Xls.Cells(lLig, 1) = CDate(TextBox701.Value)
   Xls.Cells(lLig, 2) = TextBox716.Text
    Xls.Cells(lLig, 3) = TextBox715.Text
   Xls.Cells(lLig, 5) = TextBox713.Text
   Xls.Cells(lLig, 6) = TextBox714.Value
   Xls.Cells(lLig, 7) = ComboBox153.Value
   Xls.Cells(lLig, 8) = TextBox703.Value
    Xls.Cells(lLig, 9) = TextBox704.Value
   Xls.Cells(lLig, 10) = TextBox705.Value
   Xls.Cells(lLig, 11) = TextBox706.Text
   Xls.Cells(lLig, 12) = TextBox1354.Text
   Xls.Cells(lLig, 13) = TextBox1353.Value
   Xls.Cells(lLig, 14) = TextBox709.Value
   Xls.Cells(lLig, 15) = TextBox710.Value
    Xls.Cells(lLig, 16) = TextBox711.Value
   Xls.Cells(lLig, 17) = TextBox712.Value
   Xls.Cells(lLig, 18) = TextBox717.Value
   Xls.Cells(lLig, 19) = TextBox718.Value
  [COLOR="Red"] Xls.Cells(lLig, 23) = TextBox1400.Value
   Xls.Cells(lLig, 24) = TextBox1401.Value
   Xls.Cells(lLig, 25) = TextBox1402.Value
   Xls.Cells(lLig, 26) = TextBox1403.Value
   Xls.Cells(lLig, 27) = TextBox1404.Value
   Xls.Cells(lLig, 28) = TextBox1405.Value
   Xls.Cells(lLig, 29) = TextBox1406.Value
   Xls.Cells(lLig, 30) = TextBox1407.Value
   Xls.Cells(lLig, 31) = TextBox1408.Value
   Xls.Cells(lLig, 32) = TextBox1409.Value
   Xls.Cells(lLig, 33) = TextBox1410.Value
   Xls.Cells(lLig, 34) = TextBox1411.Value
   Xls.Cells(lLig, 35) = TextBox1412.Value
   Xls.Cells(lLig, 36) = TextBox1413.Value
   Xls.Cells(lLig, 37) = TextBox1414.Value[/COLOR]

j'ai mis ce bout de code pour montrer ce que je veux

merci à tous pour votre aide
 
Dernière édition:

Statistiques des forums

Discussions
312 493
Messages
2 088 956
Membres
103 989
dernier inscrit
jralonso