• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

İki tarih arasındaki saat farkına göre gün hesabı

Katılım
29 Aralık 2005
Mesajlar
862
Excel Vers. ve Dili
Office 365 Türkçe
Herkese merhaba

Ekteki dosyada görebileceğiniz gibi arıza tarih ve saati forma giriliyor. Arıza giderildikten sonra arıza giderilme tarih ve saati giriliyor. Saat hesabını aşağıdaki kodla yaptırıyorum.

Private Sub TextBox6_Change()
tar1 = TextBox6.Text
tar1 = Format(tar1, "hh:mm")
If Len(tar1) = 5 And Len(tar2) = 5 Then
x = 1 + (CDate(tar2) - CDate(tar1))
x = Format(x, "hh:mm")
TextBox11.Text = x
End If
End Sub

Private Sub TextBox3_Change()
tar2 = TextBox3.Text
tar2 = Format(tar2, "hh:mm")
If Len(tar1) = 5 And Len(tar2) = 5 Then
x = 1 + (CDate(tar2) - CDate(tar1))
x = Format(x, "hh:mm")
TextBox11.Text = x
End If
End Sub

Ama tarih hesabını yaptırırken (formda göreceğiniz gibi) hata yapıyor. Örneğin; 25.01.2012 saat 23:14 arıza zamanı olsun. 26.01.2012 saat 01:14 arıza giderilme zamanı olsun. Bu durumda toplam duruş zamanı 0 gün 2 saat olmalı, ama benim kullandığım tarih makrosunda 1 gün olarak hesaplıyor. Kullandığım Tarih makrosu aşağıdaki gibidir:

Private Sub TextBox10_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
TextBox8.Value = Format(TextBox8.Value, "dd.mm.yyyy")
TextBox5.Value = Format(TextBox5.Value, "dd.mm.yyyy")

If TextBox5.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

If TextBox8.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

TextBox10.Value = CDate(TextBox8.Value) - CDate(TextBox5.Value)

End Sub

Ne yapmalıyım bu farkı hesaplaması için?
 

Ekli dosyalar

her yerde kar var, benim çalışmalarımdaki gibi :) . yardımcı olabilecek arkadaş var mı acaba?
 
Herkese merhaba

Ekteki dosyada görebileceğiniz gibi arıza tarih ve saati forma giriliyor. Arıza giderildikten sonra arıza giderilme tarih ve saati giriliyor. Saat hesabını aşağıdaki kodla yaptırıyorum.

Private Sub TextBox6_Change()
tar1 = TextBox6.Text
tar1 = Format(tar1, "hh:mm")
If Len(tar1) = 5 And Len(tar2) = 5 Then
x = 1 + (CDate(tar2) - CDate(tar1))
x = Format(x, "hh:mm")
TextBox11.Text = x
End If
End Sub

Private Sub TextBox3_Change()
tar2 = TextBox3.Text
tar2 = Format(tar2, "hh:mm")
If Len(tar1) = 5 And Len(tar2) = 5 Then
x = 1 + (CDate(tar2) - CDate(tar1))
x = Format(x, "hh:mm")
TextBox11.Text = x
End If
End Sub

Ama tarih hesabını yaptırırken (formda göreceğiniz gibi) hata yapıyor. Örneğin; 25.01.2012 saat 23:14 arıza zamanı olsun. 26.01.2012 saat 01:14 arıza giderilme zamanı olsun. Bu durumda toplam duruş zamanı 0 gün 2 saat olmalı, ama benim kullandığım tarih makrosunda 1 gün olarak hesaplıyor. Kullandığım Tarih makrosu aşağıdaki gibidir:

Private Sub TextBox10_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
TextBox8.Value = Format(TextBox8.Value, "dd.mm.yyyy")
TextBox5.Value = Format(TextBox5.Value, "dd.mm.yyyy")

If TextBox5.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

If TextBox8.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

TextBox10.Value = CDate(TextBox8.Value) - CDate(TextBox5.Value)

End Sub

Ne yapmalıyım bu farkı hesaplaması için?

Öncelikle tarih ve saati aynı hücreye aldım. Formatı "dd.m.yy hh:mm" yaptım.Saat kodunu aşağıdaki gibi değiştirdim.

Private Sub TextBox11_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
TextBox8.Value = Format(TextBox8.Value, "dd.m.yy hh:mm")
TextBox5.Value = Format(TextBox5.Value, "dd.m.yy hh:mm")

If TextBox5.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

If TextBox8.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

Dim a As Date, b As Date, c As Date
a = Format(TextBox5.Value, "dd.m.yy hh:nn")
b = Format(TextBox8.Value, "dd.m.yy hh:nn")
c = DateDiff("h", a, b) & ":" & DateDiff("n", a, b)


If TextBox11.Value < 24 Then TextBox11.Value = Format(c, "h:nn")' bu satır eklendi
If TextBox11.Value > 24 Then TextBox11.Value = Format(((((24 * TextBox10.Value) - DateDiff("h", a, b)) & ":" & DateDiff("n", a, b))), "h:nn")'bu satır eklendi
End Sub

Yukarıdaki makro başlangıç saati ile bitiş saati arasındaki fark 24 saati geçince çalışmıyor. çalıştırmak için yeni ifadeler ekledim ama olmadı.24 saati geçen ifadelerde 24*geçen gün sayısını hesaplanan saatten çıkarsın istiyorum.

Bir diğer konu toplam saat hesabı, bunun için kullandığım kod aşağıda;

Private Sub TextBoxx12_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
a = Format(TextBox5.Value, "dd.m.yy hh:nn")
b = Format(TextBox8.Value, "dd.m.yy hh:nn")
c = DateDiff("h", a, b) & ":" & DateDiff("n", a, b)
TextBoxx12.Value = Format(c, "h:nn")
End Sub

Burada yukarıdakinin tersine iki zaman arasındaki toplam saati bulmam lazım. iki kodda birbirine benziyor, çözümü gösterecek arkadaşlarımı çok minnettar olacağım.
 
Merhaba

Kodların son hali bu şekilde, ancak sizinde göreceğiniz gibi sonuçlarda bir hata var. Olması gereken sonuç:
Dur.Saat: 0
Dur.Gün: 3
Toplam Saat: 72 olması lazım, ancak duruş saati 0:4320 görünüyor ve bu da toplam zamana ekleniyor. Nasıl düzeltebilirim? Yardımcı olacak arkadaşlarıma şimdiden teşekkür ederim.

Duruş saati kodu:
Private Sub TextBox11_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
TextBox8.Value = Format(TextBox8.Value, "dd.m.yy hh:mm")
TextBox5.Value = Format(TextBox5.Value, "dd.m.yy hh:mm")

If TextBox5.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

If TextBox8.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

a = Format(TextBox5.Value, "dd.m.yy hh:nn")
b = Format(TextBox8.Value, "dd.m.yy hh:nn")
c = DateDiff("h", a, b) - (24 * TextBox10.Value) & ":" & DateDiff("n", a, b)
TextBox11.Value = Format(c, "h:n")
End Sub

Duruş Günü Kodu:
Private Sub TextBox10_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox8.Value = Format(TextBox8.Value, "dd.m.yy hh:mm")
TextBox5.Value = Format(TextBox5.Value, "dd.m.yy hh:mm")

If TextBox5.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

If TextBox8.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

a = Format(TextBox5.Value, "dd.m.yy hh:nn")
b = Format(TextBox8.Value, "dd.m.yy hh:nn")
c = DateDiff("d", a, b) + 1
TextBox10.Value = Format(c, "d")
End Sub

Toplam Zaman Kodu:
Private Sub TextBoxx12_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
a = Format(TextBox5.Value, "dd.m.yy hh:nn")
b = Format(TextBox8.Value, "dd.m.yy hh:nn")
c = DateDiff("h", a, b) & ":" & DateDiff("n", a, b)
TextBoxx12.Value = Format(c, "h:nn")

End Sub
 

Ekli dosyalar

  • Soru.rar
    Soru.rar
    286.8 KB · Görüntüleme: 12
Herkese iyi haftalar

Karlı bir haftaya daha merhaba derken aşağıdaki konu hakkında yardımlarınızı bekliyorum. Yardımcı olacak arkadaşlara şimdiden teşekkür ederim.

Merhaba

Kodların son hali bu şekilde, ancak sizinde göreceğiniz gibi sonuçlarda bir hata var. Olması gereken sonuç:
Dur.Saat: 0
Dur.Gün: 3
Toplam Saat: 72 olması lazım, ancak duruş saati 0:4320 görünüyor ve bu da toplam zamana ekleniyor. Nasıl düzeltebilirim? Yardımcı olacak arkadaşlarıma şimdiden teşekkür ederim.

Duruş saati kodu:
Private Sub TextBox11_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
TextBox8.Value = Format(TextBox8.Value, "dd.m.yy hh:mm")
TextBox5.Value = Format(TextBox5.Value, "dd.m.yy hh:mm")

If TextBox5.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

If TextBox8.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

a = Format(TextBox5.Value, "dd.m.yy hh:nn")
b = Format(TextBox8.Value, "dd.m.yy hh:nn")
c = DateDiff("h", a, b) - (24 * TextBox10.Value) & ":" & DateDiff("n", a, b)
TextBox11.Value = Format(c, "h:n")
End Sub

Duruş Günü Kodu:
Private Sub TextBox10_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox8.Value = Format(TextBox8.Value, "dd.m.yy hh:mm")
TextBox5.Value = Format(TextBox5.Value, "dd.m.yy hh:mm")

If TextBox5.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

If TextBox8.Value = "" Then
MsgBox " Lütfen tarih giriniz..", , ""
End If

a = Format(TextBox5.Value, "dd.m.yy hh:nn")
b = Format(TextBox8.Value, "dd.m.yy hh:nn")
c = DateDiff("d", a, b) + 1
TextBox10.Value = Format(c, "d")
End Sub

Toplam Zaman Kodu:
Private Sub TextBoxx12_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
a = Format(TextBox5.Value, "dd.m.yy hh:nn")
b = Format(TextBox8.Value, "dd.m.yy hh:nn")
c = DateDiff("h", a, b) & ":" & DateDiff("n", a, b)
TextBoxx12.Value = Format(c, "h:nn")

End Sub
 
bu soruna bir çözüm bulamayacağız galiba :(
 
Geri
Üst