Bonjour les amis,
Dans la but de m'entrainer dans la création de fonction et que cela serve à mes enfants, j'ai créé une fonction multiplication qui marche bien sur 1 seul chiffre,
donc j'ai voulu en faire une autre pour toutes les tables mais la ça coince un peu, ça continu après 10 et va pas dans le sens que je veux
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 Public Function table_multiplication2(nbre As Long) Dim col As Integer, ligdeb As Integer, nb_par_col As Integer, lig As Integer, x As Integer ligdeb = 4: col = 2: nb_par_col = 37: lig = ligdeb For x = 1 To 100 If lig = nb_par_col Then lig = ligdeb: col = col + 6 If x Like "*1" Then lig = lig + 1 Cells(lig, col).Value = nbre Cells(lig, col + 1).Value = "x" Cells(lig, col + 2).Value = x Cells(lig, col + 3).Value = "=" Cells(lig, col + 4).Value = nbre * x lig = lig + 1 Next End Function Sub test2() table_multiplication2 Range("F2").Value End Sub
j'ai essayé avec 1 to 10 mais ça me fait que la table de 1,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 Public Function table_multiplication1(nbre As Long) Dim col As Integer, ligdeb As Integer, nb_par_col As Integer, lig As Integer, x As Integer ligdeb = 4: col = 2: nb_par_col = 37: lig = ligdeb For x = 1 To 100 If lig = nb_par_col Then lig = ligdeb: col = col + 6 If x = "11" Then lig = lig + 1: x = 1: nbre = nbre + 1: Cells(lig, col).Value = nbre Cells(lig, col + 1).Value = "x" Cells(lig, col + 2).Value = x Cells(lig, col + 3).Value = "=" Cells(lig, col + 4).Value = nbre * x lig = lig + 1 Next End Function Sub test1() table_multiplication1 Range("F2").Value 'mettre 1 End Sub
et si je fait 1 to 11 ou plus, cela continu indéfiniment avec dépassement de capacité sans suivre le sens voulu
cela doit être tout bête mais je coince
Partager