raccourcire se code

gege21

XLDnaute Occasionnel
comment raccourcir ce code

Code:
If UserForm2.N1.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N1.Value 'Ac = N1
If UserForm2.N2.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N2.Value 'Ad = N2
If UserForm2.N3.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N3.Value 'Ae = N3
If UserForm2.N4.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N4.Value 'Af = N4
If UserForm2.N5.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N5.Value 'Ag = N5
If UserForm2.N6.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N6.Value 'Ah = N6
If UserForm2.N7.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N7.Value 'Ai = N7
If UserForm2.N8.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N8.Value 'Aj = N8
If UserForm2.N9.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N9.Value 'Ak = N9
If UserForm2.N10.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N10.Value 'Al = N10
If UserForm2.N11.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N11.Value 'Am = N11
If UserForm2.N12.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N12.Value 'An = N12
If UserForm2.N13.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N13.Value 'Ao = N13
If UserForm2.N14.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N14.Value 'Ap = N14
If UserForm2.N15.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N15.Value 'Aq = N15
If UserForm2.N16.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N16.Value 'Ar = N16
If UserForm2.N17.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N17.Value 'At = N17
If UserForm2.N18.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N18.Value 'Au = N18
If UserForm2.N19.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N19.Value 'Av = N19
If UserForm2.N20.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N20.Value 'Aw = N20
If UserForm2.N21.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N21.Value 'Ax = N21
If UserForm2.N22.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N22.Value 'Ay = N22
If UserForm2.N23.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N23.Value 'Az = N23
If UserForm2.N24.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N24.Value 'Ba = N24
If UserForm2.N25.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N25.Value 'Bb = N25
If UserForm2.N26.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N26.Value 'Bc = N26
If UserForm2.N27.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N27.Value 'Bd = N27
If UserForm2.N28.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N28.Value 'Be = N28
If UserForm2.N29.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.N29.Value 'Bf = N29
If UserForm2.R1.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R1.Value 'Da = R1
If UserForm2.R2.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R2.Value 'Db = R2
If UserForm2.R3.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R3.Value 'Dc = R3
If UserForm2.R4.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R4.Value 'Dd = R4
If UserForm2.R5.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R5.Value 'De = R5
If UserForm2.R6.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R6.Value 'Df = R6
If UserForm2.R7.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R7.Value 'Dg = R7
If UserForm2.R8.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R8.Value 'Dh = R8
If UserForm2.R9.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R9.Value 'Di = R9
If UserForm2.R10.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R10.Value 'Dj = R10
If UserForm2.R11.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R11.Value 'Dk = R11
If UserForm2.R12.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R12.Value 'Dl = R12
If UserForm2.R13.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R13.Value 'Dm = R13
If UserForm2.R14.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R14.Value 'Dn = R14
If UserForm2.R15.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R15.Value 'Dp = R15
If UserForm2.R16.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R16.Value 'Dq = R16
If UserForm2.R17.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R17.Value 'Dr = R17
If UserForm2.R18.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R18.Value 'Ds = R18
If UserForm2.R19.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R19.Value 'Dt = R19
If UserForm2.R20.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R20.Value 'Du = R20
If UserForm2.R21.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R21.Value 'Dv = R21
If UserForm2.R22.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R22.Value 'Dw = R22
If UserForm2.R23.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R23.Value 'Dx = R23
If UserForm2.R24.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R24.Value 'Dy = R24
If UserForm2.R25.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R25.Value 'Dz = R25
If UserForm2.R26.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R26.Value 'Ea = R26
If UserForm2.R27.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R27.Value 'Eb = R27
If UserForm2.R28.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R28.Value 'Ec = R28
If UserForm2.R29.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R29.Value 'Ed = R29
If UserForm2.R30.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R30.Value 'Ee = R30
If UserForm2.R31.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R31.Value 'Ef = R31
If UserForm2.R32.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R32.Value 'Eg = R32
If UserForm2.R33.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R33.Value 'Eh = R33
If UserForm2.R34.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R34.Value 'Ei = R34
If UserForm2.R35.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R35.Value 'Ej = R35
If UserForm2.R36.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R36.Value 'Ek = R36
If UserForm2.R37.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R37.Value 'El = R37
If UserForm2.R38.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R38.Value 'Em = R38
If UserForm2.R39.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R39.Value 'En = R39
If UserForm2.R40.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R40.Value 'Eo = R40
If UserForm2.R41.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R41.Value 'Ep = R41
If UserForm2.R42.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R42.Value 'Eq = R42
If UserForm2.R43.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R43.Value 'Er = R43
If UserForm2.R44.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R44.Value 'Es = R44
If UserForm2.R45.Value <> Sheets("record").Range("H3") Then Sheets("record").Range("H3") = UserForm2.R45.Value 'Et = R45
 

gege21

XLDnaute Occasionnel
Re : raccourcire se code

bonsoir a tous,fred0o

post trop vite fait et donc très mal fait (erreur de code...)

donc je voudrai savoir comment raccourcir se code
merci pour vos réponse

Code:
If UserForm2.N1.Value <> Sheets("record").Range("H4") Then Sheets("record").Range("H4") = UserForm2.N1.Value 'Ac = N1
If UserForm2.N2.Value <> Sheets("record").Range("H5") Then Sheets("record").Range("H5") = UserForm2.N2.Value 'Ad = N2
If UserForm2.N3.Value <> Sheets("record").Range("H6") Then Sheets("record").Range("H6") = UserForm2.N3.Value 'Ae = N3
If UserForm2.N4.Value <> Sheets("record").Range("H7") Then Sheets("record").Range("H7") = UserForm2.N4.Value 'Af = N4
If UserForm2.N5.Value <> Sheets("record").Range("H8") Then Sheets("record").Range("H8") = UserForm2.N5.Value 'Ag = N5
If UserForm2.N6.Value <> Sheets("record").Range("H9") Then Sheets("record").Range("H9") = UserForm2.N6.Value 'Ah = N6
If UserForm2.N7.Value <> Sheets("record").Range("H10") Then Sheets("record").Range("H10") = UserForm2.N7.Value 'Ai = N7
If UserForm2.N8.Value <> Sheets("record").Range("H11") Then Sheets("record").Range("H11") = UserForm2.N8.Value 'Aj = N8
If UserForm2.N9.Value <> Sheets("record").Range("H12") Then Sheets("record").Range("H12") = UserForm2.N9.Value 'Ak = N9
If UserForm2.N10.Value <> Sheets("record").Range("H13") Then Sheets("record").Range("H13") = UserForm2.N10.Value 'Al = N10
If UserForm2.N11.Value <> Sheets("record").Range("H14") Then Sheets("record").Range("H14") = UserForm2.N11.Value 'Am = N11
If UserForm2.N12.Value <> Sheets("record").Range("H15") Then Sheets("record").Range("H15") = UserForm2.N12.Value 'An = N12
If UserForm2.N13.Value <> Sheets("record").Range("H16") Then Sheets("record").Range("H16") = UserForm2.N13.Value 'Ao = N13
If UserForm2.N14.Value <> Sheets("record").Range("H17") Then Sheets("record").Range("H17") = UserForm2.N14.Value 'Ap = N14
If UserForm2.N15.Value <> Sheets("record").Range("H18") Then Sheets("record").Range("H18") = UserForm2.N15.Value 'Aq = N15
If UserForm2.N16.Value <> Sheets("record").Range("H19") Then Sheets("record").Range("H19") = UserForm2.N16.Value 'Ar = N16
If UserForm2.N17.Value <> Sheets("record").Range("H20") Then Sheets("record").Range("H20") = UserForm2.N17.Value 'At = N17
If UserForm2.N18.Value <> Sheets("record").Range("H21") Then Sheets("record").Range("H21") = UserForm2.N18.Value 'Au = N18
If UserForm2.N19.Value <> Sheets("record").Range("H22") Then Sheets("record").Range("H22") = UserForm2.N19.Value 'Av = N19
If UserForm2.N20.Value <> Sheets("record").Range("H23") Then Sheets("record").Range("H23") = UserForm2.N20.Value 'Aw = N20
If UserForm2.N21.Value <> Sheets("record").Range("H24") Then Sheets("record").Range("H24") = UserForm2.N21.Value 'Ax = N21
If UserForm2.N22.Value <> Sheets("record").Range("H25") Then Sheets("record").Range("H25") = UserForm2.N22.Value 'Ay = N22
If UserForm2.N23.Value <> Sheets("record").Range("H26") Then Sheets("record").Range("H26") = UserForm2.N23.Value 'Az = N23
If UserForm2.N24.Value <> Sheets("record").Range("H27") Then Sheets("record").Range("H27") = UserForm2.N24.Value 'Ba = N24
If UserForm2.N25.Value <> Sheets("record").Range("H28") Then Sheets("record").Range("H28") = UserForm2.N25.Value 'Bb = N25
If UserForm2.N26.Value <> Sheets("record").Range("H29") Then Sheets("record").Range("H29") = UserForm2.N26.Value 'Bc = N26
If UserForm2.N27.Value <> Sheets("record").Range("H30") Then Sheets("record").Range("H30") = UserForm2.N27.Value 'Bd = N27
If UserForm2.N28.Value <> Sheets("record").Range("H31") Then Sheets("record").Range("H31") = UserForm2.N28.Value 'Be = N28
If UserForm2.N29.Value <> Sheets("record").Range("H32") Then Sheets("record").Range("H32") = UserForm2.N29.Value 'Bf = N29
If UserForm2.R1.Value <> Sheets("record").Range("H33") Then Sheets("record").Range("H33") = UserForm2.R1.Value 'Da = R1
If UserForm2.R2.Value <> Sheets("record").Range("H34") Then Sheets("record").Range("H34") = UserForm2.R2.Value 'Db = R2
If UserForm2.R3.Value <> Sheets("record").Range("H35") Then Sheets("record").Range("H35") = UserForm2.R3.Value 'Dc = R3
If UserForm2.R4.Value <> Sheets("record").Range("H36") Then Sheets("record").Range("H36") = UserForm2.R4.Value 'Dd = R4
If UserForm2.R5.Value <> Sheets("record").Range("H37") Then Sheets("record").Range("H37") = UserForm2.R5.Value 'De = R5
If UserForm2.R6.Value <> Sheets("record").Range("H38") Then Sheets("record").Range("H38") = UserForm2.R6.Value 'Df = R6
If UserForm2.R7.Value <> Sheets("record").Range("H39") Then Sheets("record").Range("H39") = UserForm2.R7.Value 'Dg = R7
If UserForm2.R8.Value <> Sheets("record").Range("H40") Then Sheets("record").Range("H40") = UserForm2.R8.Value 'Dh = R8
If UserForm2.R9.Value <> Sheets("record").Range("H41") Then Sheets("record").Range("H41") = UserForm2.R9.Value 'Di = R9
If UserForm2.R10.Value <> Sheets("record").Range("H42") Then Sheets("record").Range("H42") = UserForm2.R10.Value 'Dj = R10
If UserForm2.R11.Value <> Sheets("record").Range("H43") Then Sheets("record").Range("H43") = UserForm2.R11.Value 'Dk = R11
If UserForm2.R12.Value <> Sheets("record").Range("H44") Then Sheets("record").Range("H44") = UserForm2.R12.Value 'Dl = R12
If UserForm2.R13.Value <> Sheets("record").Range("H45") Then Sheets("record").Range("H45") = UserForm2.R13.Value 'Dm = R13
If UserForm2.R14.Value <> Sheets("record").Range("H46") Then Sheets("record").Range("H46") = UserForm2.R14.Value 'Dn = R14
If UserForm2.R15.Value <> Sheets("record").Range("H47") Then Sheets("record").Range("H47") = UserForm2.R15.Value 'Dp = R15
If UserForm2.R16.Value <> Sheets("record").Range("H48") Then Sheets("record").Range("H48") = UserForm2.R16.Value 'Dq = R16
If UserForm2.R17.Value <> Sheets("record").Range("H49") Then Sheets("record").Range("H49") = UserForm2.R17.Value 'Dr = R17
If UserForm2.R18.Value <> Sheets("record").Range("H50") Then Sheets("record").Range("H50") = UserForm2.R18.Value 'Ds = R18
If UserForm2.R19.Value <> Sheets("record").Range("H51") Then Sheets("record").Range("H51") = UserForm2.R19.Value 'Dt = R19
If UserForm2.R20.Value <> Sheets("record").Range("H52") Then Sheets("record").Range("H52") = UserForm2.R20.Value 'Du = R20
If UserForm2.R21.Value <> Sheets("record").Range("H53") Then Sheets("record").Range("H53") = UserForm2.R21.Value 'Dv = R21
If UserForm2.R22.Value <> Sheets("record").Range("H54") Then Sheets("record").Range("H54") = UserForm2.R22.Value 'Dw = R22
If UserForm2.R23.Value <> Sheets("record").Range("H55") Then Sheets("record").Range("H55") = UserForm2.R23.Value 'Dx = R23
If UserForm2.R24.Value <> Sheets("record").Range("H56") Then Sheets("record").Range("H56") = UserForm2.R24.Value 'Dy = R24
If UserForm2.R25.Value <> Sheets("record").Range("H57") Then Sheets("record").Range("H57") = UserForm2.R25.Value 'Dz = R25
If UserForm2.R26.Value <> Sheets("record").Range("H58") Then Sheets("record").Range("H58") = UserForm2.R26.Value 'Ea = R26
If UserForm2.R27.Value <> Sheets("record").Range("H59") Then Sheets("record").Range("H59") = UserForm2.R27.Value 'Eb = R27
If UserForm2.R28.Value <> Sheets("record").Range("H60") Then Sheets("record").Range("H60") = UserForm2.R28.Value 'Ec = R28
If UserForm2.R29.Value <> Sheets("record").Range("H61") Then Sheets("record").Range("H61") = UserForm2.R29.Value 'Ed = R29
If UserForm2.R30.Value <> Sheets("record").Range("H62") Then Sheets("record").Range("H62") = UserForm2.R30.Value 'Ee = R30
If UserForm2.R31.Value <> Sheets("record").Range("H63") Then Sheets("record").Range("H63") = UserForm2.R31.Value 'Ef = R31
If UserForm2.R32.Value <> Sheets("record").Range("H64") Then Sheets("record").Range("H64") = UserForm2.R32.Value 'Eg = R32
If UserForm2.R33.Value <> Sheets("record").Range("H65") Then Sheets("record").Range("H65") = UserForm2.R33.Value 'Eh = R33
If UserForm2.R34.Value <> Sheets("record").Range("H66") Then Sheets("record").Range("H66") = UserForm2.R34.Value 'Ei = R34
If UserForm2.R35.Value <> Sheets("record").Range("H67") Then Sheets("record").Range("H67") = UserForm2.R35.Value 'Ej = R35
If UserForm2.R36.Value <> Sheets("record").Range("H68") Then Sheets("record").Range("H68") = UserForm2.R36.Value 'Ek = R36
If UserForm2.R37.Value <> Sheets("record").Range("H69") Then Sheets("record").Range("H69") = UserForm2.R37.Value 'El = R37
If UserForm2.R38.Value <> Sheets("record").Range("H70") Then Sheets("record").Range("H70") = UserForm2.R38.Value 'Em = R38
If UserForm2.R39.Value <> Sheets("record").Range("H71") Then Sheets("record").Range("H71") = UserForm2.R39.Value 'En = R39
If UserForm2.R40.Value <> Sheets("record").Range("H72") Then Sheets("record").Range("H72") = UserForm2.R40.Value 'Eo = R40
If UserForm2.R41.Value <> Sheets("record").Range("H73") Then Sheets("record").Range("H73") = UserForm2.R41.Value 'Ep = R41
If UserForm2.R42.Value <> Sheets("record").Range("H74") Then Sheets("record").Range("H74") = UserForm2.R42.Value 'Eq = R42
If UserForm2.R43.Value <> Sheets("record").Range("H75") Then Sheets("record").Range("H75") = UserForm2.R43.Value 'Er = R43
If UserForm2.R44.Value <> Sheets("record").Range("H76") Then Sheets("record").Range("H76") = UserForm2.R44.Value 'Es = R44
If UserForm2.R45.Value <> Sheets("record").Range("H77") Then Sheets("record").Range("H77") = UserForm2.R45.Value 'Et = R45
 

Softmama

XLDnaute Accro
Re : raccourcire se code

sinon ceci devrait mieux fonctionner, mais moins raccourci :


Code:
For t = 1 to 29
  Sheets("record").Range("H3").offset(t) = UserForm2.controls("N" & t)
next t
For t = 1 to 45
  Sheets("record").Range("H33").offset(t) = UserForm2.controls("R" & t)
next t
 

Softmama

XLDnaute Accro
Re : raccourcire se code

p-ê ainsi :

Code:
For t = 1 to 30
  Sheets("record").Range("H3").offset(t) = val(UserForm2.controls("N" & t))
  Sheets("record").Range("H33").offset(t) = val(UserForm2.controls("R" & t))
next t
For t = 31 to 45
  Sheets("record").Range("H33").offset(t) = val(UserForm2.controls("R" & t))
next t
 

laurent950

XLDnaute Barbatruc
Re : raccourcire se code

Bonsoir,

Peut être cela :

Sub test()
For i = 0 To 44
i = i + 1
N = "N" & i
If UserForm2.N.Value <> Sheets("record").Cells(3 + i, 8) Then Sheets("record").Cells(3 + i, 8) = UserForm2.N.Value 'Ac = N1
Next i
End Sub


laurent
 
Dernière édition:

laurent950

XLDnaute Barbatruc
Re : raccourcire se code

Bonsoir,

J'ai corrigé en faite j'ai remplacer N & i ====>>> par N

Regarde dans la macro le poste 13 j'ai apporter le correctif cel devrais être bon

laurent

Ps : Pour comprendre cela 'Ac = N1 (N1 cela correspond a quoi dans votre code) car il y a aussi "R"
 
Dernière édition:

Statistiques des forums

Discussions
314 450
Messages
2 109 731
Membres
110 553
dernier inscrit
loic55