optimisation d'un code vb avec des boutons option

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

BASSDINGUE

XLDnaute Occasionnel
BONJOUR MES DAMES ET MESSIEURS

JE VOUDRAIS SAVOIR SI IL N'Y A PAS MOYEN DE FAIRE PLUS SIMPLE QUE CE QUE J'AI PONDU 'VOIR CE QUI EST PLUS BAS".
ET EN PLUS JE VOUDRAIS QUE SI ON A OUBLIER DE COCHER DANS UNE FRAME CONTENANT DES OPTION BUTTON IL Y EST UN MESSAGE D'ERREUR AINSI QU'UN FOCUS SUR LA FRAME CONSERNEE (j'ai bien essayé mais cela ne marche pas: il tournait en boucle sur le message de la frame 2 (fr2) meme si celle ci était cochée et en plus le focus ne ce faisait pas

VOILA, POUR CE MATIN !
SI QUELQU'UN A UNE IDEE
MERCI


------------
Dim c1 As Object, c2 As Object, c3 As Object, c4 As Object, c5 As Object, c6 As Object, c7 As Object
Dim temp1 As String, temp2 As String, temp3 As String, temp4 As String, temp5 As String, temp6 As String, temp7 As String
Dim L2 As Integer

For Each c1 In Me.FR1.Controls
If c1.Value = True Then
temp1 = c1.Caption
End If
Next c1
L2 = Sheets("table_client").Range("G65536").End(xlUp).Row + 1
With Sheets("table_client")
.Range("aa" & L2).Value = temp1
End With


For Each c2 In Me.FR2A.Controls
If c2.Value = True Then
temp2 = c2.Caption
End If
Next c2
L2 = Sheets("table_client").Range("G65536").End(xlUp).Row + 1
With Sheets("table_client")
.Range("ak" & L2).Value = temp2
End With


For Each c3 In Me.FR3A.Controls
If c3.Value = True Then
temp3 = c3.Caption
End If
Next c3
L2 = Sheets("table_client").Range("G65536").End(xlUp).Row + 1
With Sheets("table_client")
.Range("av" & L2).Value = temp3
End With


For Each c4 In Me.FR4A.Controls
If c4.Value = True Then
temp4 = c4.Caption
End If
Next c4
L2 = Sheets("table_client").Range("G65536").End(xlUp).Row + 1
With Sheets("table_client")
.Range("bg" & L2).Value = temp4
End With


For Each c5 In Me.FR5.Controls
If c5.Value = True Then
temp5 = c5.Caption
End If
Next c5
L2 = Sheets("table_client").Range("G65536").End(xlUp).Row + 1
With Sheets("table_client")
.Range("z" & L2).Value = temp5
End With


For Each c6 In Me.FR6.Controls
If c6.Value = True Then
temp6 = c6.Caption
End If
Next c6
L2 = Sheets("table_client").Range("G65536").End(xlUp).Row + 1
With Sheets("table_client")
.Range("bj" & L2).Value = temp6
End With


For Each c7 In Me.FR7.Controls
If c7.Value = True Then
temp7 = c7.Caption
End If
Next c7
L2 = Sheets("table_client").Range("G65536").End(xlUp).Row + 1
With Sheets("table_client")
.Range("bl" & L2).Value = temp7
End With
 
Re : optimisation d'un code vb avec des boutons option

bonjour BASSDINGUE

Je n'ai pas testé (et pour cause !!)
Essaie donc ceci , et si cela tourne je regarderai plus avant

Code:
col = Array("aa", "ak", "av", "bg", "z", "bj", "bl")
For n = 0 To Me.Controls.Count - 1
 If InStr(Me.Controls(n).Name, "FR") <> 0 Then
  For m = 0 To Me.Controls(n).Controls.Count - 1
    If Me.Controls(n).Controls(m).Value = True Then
      temp = Me.Controls(n).Controls(m).Caption
    End If
  Next m
  L2 = Sheets("table_client").Range("G65536").End(xlUp).Row + 1
  With Sheets("table_client")
    .Range(col(n) & L2).Value = temp
  End With
 End If
Next n

Ps: fais egalement un tour du coté de la charte pour voir a quoi correspondent les majuscules
 
Re : optimisation d'un code vb avec des boutons option

re bjr pierrejean

pour l'ambigu, j'ai resolu le probleme de facons radicale: j'ai repris une version anterieur et j'ai recommencer . et ca m'arche
parcompte j'ai remarqué que la base qui a plantée est 2 fois + lourd que l'autre .Le probleme vient peut etre en rapport avec ca

merci pour les variable j'essaye et je te dit ce qu'il en ai
 
Re : optimisation d'un code vb avec des boutons option

Re

As-tu

option Base 1 ??

Si oui : a supprimer

Sinon cela peut vouloir dire qu'il n'y a pas suffisamment de colonnes par rapport aux Frames

met un

Msgbox(n)

avant la ligne .Range(col(n) & L2).Value = temp et dis nous ce qu'elle affiche avant le bug ainsi que le nombre de Frames

Note egalement qu'un fichier exemple avec uniquement les elements concernés par le problème nous permettrait de t'aider bien plus rapidement
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
4
Affichages
736
Réponses
4
Affichages
756
Réponses
3
Affichages
924
Réponses
3
Affichages
432
Retour