SOLVED

Multiple calcule par case ou cellule

Copper Contributor

Bonjours tout le monde

J'essais de faire un tableau de calcule de :

semaine , bimensuel, mois et année. je cherche a entrer 3 fonctions par case. je m'explique:

Si j'entre un montant dans semaine comme 100$ je veut que sa affiche 200 dans bimensuel, 400 dans mois et 5200 dans année mais je voudrais aussi être capable d'entrer un montant comme juste 400 dans mois et que les calcule de semaine, bimensuel et année se font automatiquement. pour sa je dois faire, je crois, 3 calcule par case. un Si ou un Ou d'après moi. comme 400 pour mois je ferais:

=400/4 ou 400/2 ou 400*12

mais je ne sais pas comment mettre les 3 formule dans une même case pour arriver a mes fin alors si vous avez une idée ce serais utile. Merci beaucoup

 

1 Reply
best response confirmed by EskWaD (Copper Contributor)
Solution

@EskWaD 

This requires VBA in the worksheet module. Assuming that the amounts will be in A2:D30:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Not Intersect(Range("A2:D30"), Target) Is Nothing Then
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        Select Case Target.Column
            Case 1 ' A = semaine
                If IsNumeric(Target.Value) Then
                    Target.Offset(0, 1).Value = Target.Value * 2
                    Target.Offset(0, 2).Value = Target.Value * 4
                    Target.Offset(0, 3).Value = Target.Value * 52
                Else
                    Target.Offset(0, -1).ClearContents
                    Target.Offset(0, 1).ClearContents
                    Target.Offset(0, 2).ClearContents
                End If
            Case 2 ' B = bimensuel
                If IsNumeric(Target.Value) Then
                    Target.Offset(0, -1).Value = Target.Value / 2
                    Target.Offset(0, 1).Value = Target.Value * 2
                    Target.Offset(0, 2).Value = Target.Value * 26
                Else
                    Target.Offset(0, 1).ClearContents
                    Target.Offset(0, 2).ClearContents
                    Target.Offset(0, 3).ClearContents
                End If
            Case 3 ' C = mois
                If IsNumeric(Target.Value) Then
                    Target.Offset(0, -2).Value = Target.Value / 4
                    Target.Offset(0, -1).Value = Target.Value / 2
                    Target.Offset(0, 1).Value = Target.Value * 12
                Else
                    Target.Offset(0, -2).ClearContents
                    Target.Offset(0, -1).ClearContents
                    Target.Offset(0, 1).ClearContents
                End If
            Case 4 ' D = année
                If IsNumeric(Target.Value) Then
                    Target.Offset(0, -3).Value = Target.Value / 52
                    Target.Offset(0, -2).Value = Target.Value / 26
                    Target.Offset(0, -1).Value = Target.Value / 12
                Else
                    Target.Offset(0, -3).ClearContents
                    Target.Offset(0, -2).ClearContents
                    Target.Offset(0, -1).ClearContents
                End If
        End Select
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    End If
End Sub

See the attached workbook. It is a .xlsm workbook, an you'll have to allow macros when you open it.

1 best response

Accepted Solutions
best response confirmed by EskWaD (Copper Contributor)
Solution

@EskWaD 

This requires VBA in the worksheet module. Assuming that the amounts will be in A2:D30:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Not Intersect(Range("A2:D30"), Target) Is Nothing Then
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        Select Case Target.Column
            Case 1 ' A = semaine
                If IsNumeric(Target.Value) Then
                    Target.Offset(0, 1).Value = Target.Value * 2
                    Target.Offset(0, 2).Value = Target.Value * 4
                    Target.Offset(0, 3).Value = Target.Value * 52
                Else
                    Target.Offset(0, -1).ClearContents
                    Target.Offset(0, 1).ClearContents
                    Target.Offset(0, 2).ClearContents
                End If
            Case 2 ' B = bimensuel
                If IsNumeric(Target.Value) Then
                    Target.Offset(0, -1).Value = Target.Value / 2
                    Target.Offset(0, 1).Value = Target.Value * 2
                    Target.Offset(0, 2).Value = Target.Value * 26
                Else
                    Target.Offset(0, 1).ClearContents
                    Target.Offset(0, 2).ClearContents
                    Target.Offset(0, 3).ClearContents
                End If
            Case 3 ' C = mois
                If IsNumeric(Target.Value) Then
                    Target.Offset(0, -2).Value = Target.Value / 4
                    Target.Offset(0, -1).Value = Target.Value / 2
                    Target.Offset(0, 1).Value = Target.Value * 12
                Else
                    Target.Offset(0, -2).ClearContents
                    Target.Offset(0, -1).ClearContents
                    Target.Offset(0, 1).ClearContents
                End If
            Case 4 ' D = année
                If IsNumeric(Target.Value) Then
                    Target.Offset(0, -3).Value = Target.Value / 52
                    Target.Offset(0, -2).Value = Target.Value / 26
                    Target.Offset(0, -1).Value = Target.Value / 12
                Else
                    Target.Offset(0, -3).ClearContents
                    Target.Offset(0, -2).ClearContents
                    Target.Offset(0, -1).ClearContents
                End If
        End Select
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    End If
End Sub

See the attached workbook. It is a .xlsm workbook, an you'll have to allow macros when you open it.

View solution in original post