Reduction code macro

  • Initiateur de la discussion robert51
  • Date de début
R

robert51

Guest
Salut à tous,

Quelqun connait il un moyen de simplifier mon code.

If TextBox5.Visible = False Then TextBox5.Value = ''
If TextBox6.Visible = False Then TextBox6.Value = ''
If TextBox7.Visible = False Then TextBox7.Value = ''
If TextBox8.Visible = False Then TextBox8.Value = ''
If TextBox9.Visible = False Then TextBox9.Value = ''
If TextBox10.Visible = False Then TextBox10.Value = ''
If TextBox11.Visible = False Then TextBox11.Value = ''
If TextBox12.Visible = False Then TextBox12.Value = ''
If TextBox13.Visible = False Then TextBox13.Value = ''
If TextBox14.Visible = False Then TextBox14.Value = ''
If TextBox15.Visible = False Then TextBox15.Value = ''
If TextBox16.Visible = False Then TextBox16.Value = ''
If TextBox17.Visible = False Then TextBox17.Value = ''
If TextBox18.Visible = False Then TextBox18.Value = ''
If TextBox19.Visible = False Then TextBox19.Value = ''

et celui-ci

ange('B5').Value = TextBox5.Value
Range('c5').Value = TextBox6.Value
Range('d5').Value = TextBox7.Value
Range('e5').Value = TextBox8.Value
Range('B6').Value = TextBox9.Value
Range('c6').Value = TextBox10.Value
Range('d6').Value = TextBox11.Value
Range('e6').Value = TextBox12.Value
Range('b7').Value = TextBox13.Value
Range('c7').Value = TextBox14.Value
Range('d7').Value = TextBox15.Value
Range('e7').Value = TextBox16.Value
Range('b8').Value = TextBox17.Value
Range('c8').Value = TextBox18.Value
Range('d8').Value = TextBox19.Value
Range('e8').Value = TextBox20.Value
Range('B9').Value = TextBox21.Value
Range('c9').Value = TextBox22.Value
Range('d9').Value = TextBox23.Value
Range('e9').Value = TextBox24.Value



merci à tous
 

myDearFriend!

XLDnaute Barbatruc
Bonsoir robert51, le Forum,

Pour le premier, tu peux essayer :
Dim i As Byte
      For i = 5 To 19
            If Not Controls('TextBox' & i).Visible Then
                  Controls('TextBox' & i) = ''
            End If
      Next i
Pour le deuxième :
Dim i As Byte, L As Byte, C As Byte
      L = 5
      C = 1
      For i = 1 To 20
            C = C + 1
            Cells(L, C).Value = Controls('TextBox' & i + 4).Value
            If i Mod 4 = 0 Then
                  L = L + 1
                  C = 1
            End If
      Next i
Cordialement,
 

Robert

XLDnaute Barbatruc
Repose en paix
Bonsoir Robert, Didier, bonsoir le forum,

Argh !!! Didier m'a encore devancé... Tant pis, j'envoie ma proposition (proche de la sienne par ailleurs, sauf que la sienne est toujours plus claire et ça ménerve...)

premier cas :

Dim x As Byte
For x = 5 To 19
If Me.Controls('TextBox' & x).Visible = False Then Me.Controls('TextBox' & x).Value = ''
Next x

second cas :

Dim y As Byte, l As Byte

For y = 5 To 24
l = 4 + (y - 1) \\\\\\\\ 4
Cells(l, ((y - 1) Mod 4) + 2).Value = Me.Controls('Textbox' & y).Value
Next y

Message édité par: Robert, à: 02/03/2006 22:31
 

Statistiques des forums

Discussions
312 329
Messages
2 087 331
Membres
103 519
dernier inscrit
Thomas_grc11