VBA créé une variable à l'aide d'un integer

Fermé
vincs333 - 12 mai 2018 à 18:43
yg_be Messages postés 22724 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 25 avril 2024 - 12 mai 2018 à 22:51
Bonjour,

Je souhaite pouvoir appeler une procédure sur plusieurs variable
exemple :
Mes variables lot1 , lot2 , ..., lot20 contiennent des données en chiffre elles sont précedemment créés dans mon code


Dim i as integer
for i = 1 to 20 (j'ai aussi essayé for i = "lot" & 1 to "lot" & 20 mais cela me créé un texte et nom une variable utilisable)
ilot = "lot" & i (cela me créé la variable ilot en string (donc non utilisable) et non une variable lot3 par exemple contenent un nombre)

call compterlot(ilot)

next i


Merci d'avance pour vos idées (je suis aussi preneur si vous savez transformer un string en variable utilisable)

3 réponses

NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 331
12 mai 2018 à 18:47
Utilise un tableau, c'est plus adapté pour cet usage.
0
Je ne peux pas c'est un fichier word qui importe des données dans des fichiers excels (planning, rotation de lot de fabrication pour une usine) je les "sauvegarde temporairement" dans des textbox pour traiter les données et enfin les implanter dans un tableau "word" pour qu'il soit imprimer
0
NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 331
12 mai 2018 à 18:53
Tu peux regarder la collection "Controls" de ta userform alors.
0
j'utilise deja le controls :

Sub saisielot()
saisie = 0
For i = 1 To 36
ilot = (i * 3) - 2
Call compterlot(ilot, i, lot)

If lot <> 0 And saisie = 0 Then
lot1 = lot
nom1 = UserForm2.Controls("textbox" & ilot)
saisie = saisie + 1
End If

If lot <> 0 And saisie = 1 And nom1 <> UserForm2.Controls("textbox" & ilot) Then
lot2 = lot
nom2 = UserForm2.Controls("textbox" & ilot)
saisie = saisie + 1
End If

If lot <> 0 And saisie = 2 And nom2 <> UserForm2.Controls("textbox" & ilot) Then
lot3 = lot
nom3 = UserForm2.Controls("textbox" & ilot)
saisie = saisie + 1
End If

If lot <> 0 And saisie = 3 And nom3 <> UserForm2.Controls("textbox" & ilot) Then
lot4 = lot
nom4 = UserForm2.Controls("textbox" & ilot)
saisie = saisie + 1
End If

If lot <> 0 And saisie = 4 And nom4 <> UserForm2.Controls("textbox" & ilot) Then
lot5 = lot
nom5 = UserForm2.Controls("textbox" & ilot)
saisie = saisie + 1
End If

If lot <> 0 And saisie = 5 And nom5 <> UserForm2.Controls("textbox" & ilot) Then
lot6 = lot
nom6 = UserForm2.Controls("textbox" & ilot)
saisie = saisie + 1
End If

If lot <> 0 And saisie = 6 And nom6 <> UserForm2.Controls("textbox" & ilot) Then
lot7 = lot
nom7 = UserForm2.Controls("textbox" & ilot)
saisie = saisie + 1
End If

If lot <> 0 And saisie = 7 And nom7 <> UserForm2.Controls("textbox" & ilot) Then
lot8 = lot
nom8 = UserForm2.Controls("textbox" & ilot)
saisie = saisie + 1
End If

If lot <> 0 And saisie = 8 And nom8 <> UserForm2.Controls("textbox" & ilot) Then
lot9 = lot
nom9 = UserForm2.Controls("textbox" & ilot)
saisie = saisie + 1
End If

If lot <> 0 And saisie = 9 And nom9 <> UserForm2.Controls("textbox" & ilot) Then
lot10 = lot
nom10 = UserForm2.Controls("textbox" & ilot)
saisie = saisie + 1
End If

Next i


For jlot = "lot" & 1 To "lot" & 10

call laprocedurequejesouhaite(jlot) <------------------------- c'est ici mon probleme

Next jlot



End Sub

Sub compterlot(ilot, i, lot)
lot = 0
blocage5 = 0
For g = 1 To 36
glot = (g * 3) - 2
If glot > ilot Then
If UserForm2.Controls("textbox" & ilot) <> UserForm2.Controls("textbox" & glot) And blocage5 = 0 Then
lot = g - i
blocage5 = 1
End If
End If
If g = 36 And blocage5 = 0 And UserForm2.Controls("textbox" & glot) <> Empty Then
lot = g - i + 1
End If

Next g


End Sub
0
yg_be Messages postés 22724 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 25 avril 2024 1 476
12 mai 2018 à 22:51
bonsoir, utiliser un tableau, c'est faire
tlot(1) = lot
au lieu de
 lot1 = lot
, et ensuite,
ilot = tlot(i)
0