Calculer nombre d'heures VBA Excel

Bonjour,

Voici mon problème :

Je dois calculer nombre d'heures, entre Colonne(J) et Colonne(K) et Colonne(L) et le resultat dans la Colonne(M).

Par exemple :

if i = 13 then

.Cells(lign, i).FormulaR1C1 = "=RC[-3]-RC[-2]+RC[-1]"

exemple2:

 if i = 13 then
Controls("Textbox" & i) = Controls("Textbox" & i - 3) - Controls("Textbox" & i - 2) + Controls("Textbox" & i - 1)

J'ai trouvé du code sur le forum mais je n'arrive pas à l' adapter.

MRCI BIEN DE VOTRE AIDE

Bonjour

Un essai. Te convient-il ?

Bye !

9classeur1-v1.xlsm (23.13 Ko)

bonjour

Merci à l'avance pour votre aide, et j'attends votre réponse

si les heures et sup a 24H donne 00:00

Si tu peux me corrige le code suivant

Option Explicit
Private Sub CommandButton1_Click()
Dim i&, fin&
  If modif Then
    With Feuil2
      For i = 1 To 14
        .Cells(lign, i) = Controls("Textbox" & i): Controls("Textbox" & i) = ""
      Next i
    End With
    Unload Me: GoTo 1
  End If
  If TextBox1 <> "" And TextBox2 <> "" And TextBox3 <> "" And TextBox4 <> "" Or TextBox5 <> "" And TextBox6 <> "" Then
    With Feuil2
      fin = .Range("A" & Rows.Count).End(xlUp).Row + 1
      For i = 1 To 14
        .Cells(fin, i) = Controls("Textbox" & i): Controls("Textbox" & i) = ""
       If i = 13 Then
       .Cells(lign, i).FormulaR1C1 = "=RC[-3]-RC[-2]+RC[-1]"
       Me.TextBox13 = Sheets("Feuil2").Cells(lign, i)

        End If
      Next i

    End With

  Else
    MsgBox "Veuillez remplir au minimum les éléments suivants : Nom, Prénom", , "Manque de données": Exit Sub
1 End If
  Call Classer
  'Unload Me
  If modif Then
    rech = UserForm1.TextBox1: Unload UserForm1: UserForm1.TextBox1 = rech: UserForm1.Show:
  End If
  modif = 0
End Sub

Private Sub UserForm_Initialize()
Dim i&
  With Feuil2
    For i = 1 To 14
      Controls("Label" & i) = .Cells(1, i)
    Next i
  End With
End Sub

merci


je bloque ici

 If i = 13 Then
       .Cells(lign, i).FormulaR1C1 = "=RC[-3]-RC[-2]+RC[-1]"
       Me.TextBox13 = Sheets("Feuil2").Cells(lign, i)

        End If

Bonjour

J'essaie avec ce code mais il reste meme probleme.

With Feuil2
      fin = .Range("A" & Rows.Count).End(xlUp).Row + 1
      For i = 1 To 14
        .Cells(fin, i) = Controls("Textbox" & i): Controls("Textbox" & i) = ""
        If i = 10 Then
        Me.TextBox10 = .Cells(fin, i)
        ElseIf i = 11 Then
        Me.TextBox11 = .Cells(fin, i)
        ElseIf i = 12 Then
        Me.TextBox12 = .Cells(fin, i)
        ElseIf i = 13 Then
        Me.TextBox13 = .Cells(fin, i)

        .Cells(fin, i).FormulaR1C1 = "=RC[-3]-RC[-2]+RC[-1]"
        Me.TextBox13 = Sheets("Feuil2").Cells(fin, i)

        End If
      Next i

    End With
7casseur-v01.xlsm (60.25 Ko)

Tu as cette instruction :

With Feuil2

Mais dans ton fichier, il n'y a pas de ''Feuil2''

Bye !

bonjour

pardon je rectif le code :

With sheets("Base")
      fin = .Range("A" & Rows.Count).End(xlUp).Row + 1
      For i = 1 To 14
        .Cells(fin, i) = Controls("Textbox" & i): Controls("Textbox" & i) = ""
        If i = 10 Then
        Me.TextBox10 = .Cells(fin, i)
        ElseIf i = 11 Then
        Me.TextBox11 = .Cells(fin, i)
        ElseIf i = 12 Then
        Me.TextBox12 = .Cells(fin, i)
        ElseIf i = 13 Then
        Me.TextBox13 = .Cells(fin, i)

        .Cells(lign, i).FormulaR1C1 = "=RC[-3]-RC[-2]+RC[-1]"
        Me.TextBox13 = Sheets("Base").Cells(lign, i)

        End If
      Next i

    End With

cdt

6classeur-v01.xlsm (61.21 Ko)

Ta variable lign n'est pas définie et ne représente rien.

Essaie en remplaçant lign par fin :

 .Cells(fin, i).FormulaR1C1 = "=RC[-3]-RC[-2]+RC[-1]"
 Me.TextBox13 = Sheets("Base").Cells(fin, i)

Bye !

bonjour

range("M") ne s'affiche pas (en colonne M : Temp13 = (Temp10- Temp11) + Temp12)

merci de votre aide

6classeur-v01.xlsm (60.99 Ko)

Bonjour

Je ne vois pas ce qui cloche.

Sur mon PC, la macro me bien la bonne formule en colonne M...

Bye !

5classeur-v02.xlsm (52.40 Ko)

bonjour

je fais un modif ,mais quand je click deux fois sur listbox il donne un bug

tu peus me corriger le code

merci

7classeur-v02.xlsm (61.81 Ko)

Désolé mais je ne vois pas.

J'abandonne.

Bye !

bonjour

l'ajout en 4 colonne (J,K,L,M) Ca marche tres bien

mais en d'autres colonne ca marche pas !

je ne sais pas pourquoi?

10classeur-v02-1.xlsm (60.90 Ko)

Bonjour

thank you very much for your help gmb

je bloque ici mais je ne trouve pas la solution !

cdt

bonjour

Up

cdt

bonjour

je trouve une solution mais pas satisfait

--- quand il y a des cases (cellules) vide au Sheets("Base"), le remplissage des cellules et perturbes

il ne garde pas l'ordre de remplissage des lignes

est ce que normale ca ??

cdt

Rechercher des sujets similaires à "calculer nombre heures vba"