Simplification code VBA

maninwhite

XLDnaute Occasionnel
Bonjour à toutes et à tous

Je reviens vers vous afin d'obtenir de l'aide pour la simplification des deux codes ci dessous.

Je pense que par exemple pour le deuxième code un "select case" serait plus approprié.

Merci pour votre aide

Code:
'Remplir colonne ok
    Cells(3, col_semaine) = Cells(3, col_semaine) + ComboBox_comportement_ok_admin1
    Cells(4, col_semaine) = Cells(4, col_semaine) + ComboBox_comportement_ok_admin2
    Cells(5, col_semaine) = Cells(5, col_semaine) + ComboBox_comportement_ok_admin3
    Cells(6, col_semaine) = Cells(6, col_semaine) + ComboBox_comportement_ok_admin4
    Cells(7, col_semaine) = Cells(7, col_semaine) + ComboBox_comportement_ok_admin5

    'Remplir colonne nok
    Cells(3, col_semaine + 1) = Cells(3, col_semaine + 1) + ComboBox_comportement_nok_admin1
    Cells(4, col_semaine + 1) = Cells(4, col_semaine + 1) + ComboBox_comportement_nok_admin2
    Cells(5, col_semaine + 1) = Cells(5, col_semaine + 1) + ComboBox_comportement_nok_admin3
    Cells(6, col_semaine + 1) = Cells(6, col_semaine + 1) + ComboBox_comportement_nok_admin4
    Cells(7, col_semaine + 1) = Cells(7, col_semaine + 1) + ComboBox_comportement_nok_admin5

    'Remplir colonne feedback positif
    Cells(3, col_semaine + 2) = Cells(3, col_semaine + 2) + ComboBox_feedback_positif_admin1
    Cells(4, col_semaine + 2) = Cells(4, col_semaine + 2) + ComboBox_feedback_positif_admin2
    Cells(5, col_semaine + 2) = Cells(5, col_semaine + 2) + ComboBox_feedback_positif_admin3
    Cells(6, col_semaine + 2) = Cells(6, col_semaine + 2) + ComboBox_feedback_positif_admin4
    Cells(7, col_semaine + 2) = Cells(7, col_semaine + 2) + ComboBox_feedback_positif_admin5

    'Remplir colonne feedback positif
    Cells(3, col_semaine + 3) = Cells(3, col_semaine + 3) + ComboBox_feedback_constructif_admin1
    Cells(4, col_semaine + 3) = Cells(4, col_semaine + 3) + ComboBox_feedback_constructif_admin2
    Cells(5, col_semaine + 3) = Cells(5, col_semaine + 3) + ComboBox_feedback_constructif_admin3
    Cells(6, col_semaine + 3) = Cells(6, col_semaine + 3) + ComboBox_feedback_constructif_admin4
    Cells(7, col_semaine + 3) = Cells(7, col_semaine + 3) + ComboBox_feedback_constructif_admin5



Code:
    If TextBox_service_associe = "A" Then

        With Sheets("Ad")
            With .Cells(.Range("A:A").Find(TextBox_date).Row, .Range("1:1").Find(TextBox_nom_prenom).Column)
                If .Value = "" Then
                    .Value = "1"
                Else
                    .Value = .Value + 1
                End If
            End With
        End With
    End If

    If TextBox_service_associe = "L" Then

        With Sheets("L")
            With .Cells(.Range("A:A").Find(TextBox_date).Row, .Range("1:1").Find(TextBox_nom_prenom).Column)
                If .Value = "" Then
                    .Value = "1"
                Else
                    .Value = .Value + 1
                End If
            End With
        End With
    End If

    If TextBox_service_associe = "M" Then

        With Sheets("M")
            With .Cells(.Range("A:A").Find(TextBox_date).Row, .Range("1:1").Find(TextBox_nom_prenom).Column)
                If .Value = "" Then
                    .Value = "1"
                Else
                    .Value = .Value + 1
                End If
            End With
        End With
    End If

    If TextBox_service_associe = "P" Then

        With Sheets("")
            With .Cells(.Range("A:A").Find(TextBox_date).Row, .Range("1:1").Find(TextBox_nom_prenom).Column)
                If .Value = "" Then
                    .Value = "1"
                Else
                    .Value = .Value + 1
                End If
            End With
        End With
    End If

    If TextBox_service_associe = "" Then

        With Sheets("Qualité")
            With .Cells(.Range("A:A").Find(TextBox_date).Row, .Range("1:1").Find(TextBox_nom_prenom).Column)
                If .Value = "" Then
                    .Value = "1"
                Else
                    .Value = .Value + 1
                End If
            End With
        End With
    End If

    If TextBox_service_associe = "" Then

        With Sheets("TSM")
            With .Cells(.Range("A:A").Find(TextBox_date).Row, .Range("1:1").Find(TextBox_nom_prenom).Column)
                If .Value = "" Then
                    .Value = "1"
                Else
                    .Value = .Value + 1
                End If
            End With
        End With
    End If
 

Paf

XLDnaute Barbatruc
Re : Simplification code VBA

Bonjour à tous,

pour le deuxième code

Code:
 Select Case TextBox_service_associe 
       Case  "A" 
                   MaFeuille="Ad"
       Case "L"
                   MaFeuille="L"

       Case   ......

End Select

        With Sheets(MaFeuille)
            With .Cells(.Range("A:A").Find(TextBox_date).Row, .Range("1:1").Find(TextBox_nom_prenom).Column)
                If .Value = "" Then
                    .Value = "1"
                Else
                    .Value = .Value + 1
                End If
            End With
        End With

A+
 

Yaloo

XLDnaute Barbatruc
Re : Simplification code VBA

Re,

Tu peux aussi remplacer :
VB:
If .Value = "" Then
                     .Value = "1"
                 Else
                     .Value = .Value + 1
                 End If
par
VB:
.Value = IIf(.Value = "", 1, .Value + 1)

Pour t'aider davantage, tu pourrais peut-être créer un fichier bidon avec la même conception de classeur ou bien utiliser l'"anonymisateur" de Roger, vois ici

A+

Martial
 

Yaloo

XLDnaute Barbatruc
Re : Simplification code VBA

Re,

Pour la première partie, peut-être, mais c'est pas sûr (car pas pu tester)
VB:
Dim Combo(), i&, j&
Combo = Array("ComboBox_comportement_ok_admin", "ComboBox_comportement_nok_admin", "ComboBox_feedback_positif_admin", "ComboBox_feedback_constructif_admin")
For i = 0 To 3
  For j = 1 To 5
    Cells(j + 2, col_semaine + i) = Cells(3, col_semaine + i) + Controls(Combo(i) & j)
  Next
Next

A+
 

Statistiques des forums

Discussions
312 843
Messages
2 092 758
Membres
105 527
dernier inscrit
GPGA45