Greetings community!
I am trying to write the following VBA code but something is not working.
Take a look please, maybe I'm missing something and help me with a solution.
The VBA code should calculate intervals greater than 24 hours between 2 dates at different times (dd.mm.yyyy hh:mm), located in different columns on the spreadsheet, and return a value in the HOME1 sheet on the column H of the form hh:mm or hh:mm:ss. Likewise in the sheets HOME2 and HOME3 on cells columns I and J respectively.
Thank you in advance!
============================================================================================
Public Function Durate(dday As Double) As String
Dim s As String
Dim minute As Long
Dim hour As Long
Dim RestMinute As Long
If dday < 0 Then
s = "_"
minute = dday * 24 * 60 * (-1)
Else
s = ""
minute = dday * 24 * 60
End If
RestMinute = minute Mod 60
hour = (minute - RestMinute) / 60
If hour < 10 Then s = s & "0"
s = s & hour & ":"
If RestMinute < 10 Then s = s & "0"
s = s & RestMinute
Durate = s
End Function
Sub CalculDurate()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
' For HOME1
Set ws = ThisWorkbook.Sheets("HOME1")
lastRow = ws.Cells(ws.Rows.Count, 8).End(xlUp).Row
For i = 2 To lastRow
ws.Cells(i, 8).Value = Durate(ws.Cells(i, 8).Value)
Next i
' For HOME2
Set ws = ThisWorkbook.Sheets("HOME2")
lastRow = ws.Cells(ws.Rows.Count, 6).End(xlUp).Row
For i = 2 To lastRow
ws.Cells(i, 6).Value = Durate(ws.Cells(i, 6).Value)
Next i
' For HOME3
Set ws = ThisWorkbook.Sheets("HOME3")
lastRow = ws.Cells(ws.Rows.Count, 12).End(xlUp).Row
For i = 2 To lastRow
ws.Cells(i, 12).Value = Durate(ws.Cells(i, 12).Value)
Next i
End Sub
The VBA code should calculate intervals greater than 24 hours between 2 dates at different times
Înapoi la “Visual Basic for Application (VBA) cu Excel - Intrebari tehnice”
Mergi la
- Administrative
- ↳ Anunturi
- ↳ Concursuri
- ↳ Condica de sugestii si reclamatii
- Comunitati IT Learning
- ↳ Office Specialist: Comunitatea Microsoft Office din Romania
- ↳ Microsoft Excel - Intrebari tehnice (legatura catre forumul dedicat Dr.Excel)
- ↳ Microsoft Access - Intrebari tehnice
- ↳ Invata Microsoft Access cu Echipa IT Learning
- ↳ Intrebari despre Access 2019
- ↳ Intrebari despre Access 2016
- ↳ Intrebari despre Access 2013
- ↳ Intrebari despre Access 2010
- ↳ Intrebari despre Access 2007
- ↳ Intrebari despre Access 2003
- ↳ Tips and tricks in Access (indiferent de versiune)
- ↳ Microsoft Word - Intrebari tehnice
- ↳ Invata Microsoft Word cu Echipa IT Learning
- ↳ Intrebari despre Word 2019
- ↳ Intrebari despre Word 2016
- ↳ Intrebari despre Word 2013
- ↳ Intrebari despre Word 2010
- ↳ Intrebari despre Word 2007
- ↳ Intrebari despre Word 2003
- ↳ Tips and tricks in Word (indiferent de versiune)
- ↳ Microsoft Outlook - Intrebari tehnice
- ↳ Invata Microsoft Outlook cu Echipa IT Learning
- ↳ Intrebari despre Outlook 2019
- ↳ Intrebari despre Outlook 2016
- ↳ Intrebari despre Outlook 2013
- ↳ Intrebari despre Outlook 2010
- ↳ Intrebari despre Outlook 2007
- ↳ Intrebari despre Outlook 2003
- ↳ Tips and tricks in Outlook (indiferent de versiune)
- ↳ Microsoft Powerpoint- Intrebari tehnice
- ↳ Invata Microsoft Powerpoint cu Echipa IT Learning
- ↳ Intrebari despre Powerpoint 2019
- ↳ Intrebari despre Powerpoint 2016
- ↳ Intrebari despre Powerpoint 2013
- ↳ Intrebari despre Powerpoint 2010
- ↳ Intrebari despre Powerpoint 2007
- ↳ Intrebari despre Powerpoint 2003
- ↳ Tips and tricks in Powerpoint (indiferent de versiune)
- ↳ Visual Basic for Application (VBA) - Intrebari tehnice
- ↳ Invata sa programezi in VBA de la Echipa IT Learning
- ↳ Alte programe din suita Microsoft Office
- ↳ Invata Microsoft Project cu Echipa IT Learning
- ↳ Dr.Excel: Comunitatea Microsoft Excel din Romania
- ↳ Microsoft Excel - Intrebari tehnice
- ↳ Invata Microsoft Excel cu Echipa Dr.Excel
- ↳ Intrebari despre Excel 2019
- ↳ Intrebari despre Excel 2016
- ↳ Intrebari despre Excel 2013
- ↳ Intrebari despre Excel 2010
- ↳ Intrebari despre Excel 2007
- ↳ Intrebari despre Excel 2003
- ↳ Tips and Tricks Excel
- ↳ Probleme cu aplicatiile ce folosesc Excel ca aplicatie ajutatoare
- ↳ Visual Basic for Application (VBA) cu Excel - Intrebari tehnice
- ↳ Invata sa programezi in VBA de la Echipa Dr.VBA
- ↳ Power Query & Power Pivot
- ↳ Dr.Windows: Comunitatea Microsoft Windows din Romania
- ↳ Microsoft Windows - Intrebari tehnice
- ↳ Invata Microsoft Windows cu Echipa IT Learning
- ↳ Intrebari despre Windows 10
- ↳ Intrebari despre Windows 8
- ↳ Intrebari despre Windows 7
- ↳ Intrebari despre Windows Vista
- ↳ Intrebari despre Windows XP
- ↳ Intrebari despre ALTE versiuni de Windows
- Servicii IT Learning
- ↳ Despre cursurile in clasa
- ↳ Despre cursurile online (www.office-learning.ro)
- ↳ Discutii despre Cursurile Office-Learning
- ↳ Cursurile interactive de Excel
- ↳ Cursurile interactive de Access
- ↳ Cursurile interactive de Powerpoint
- ↳ Cursurile interactive de Word
- ↳ Cursurile interactive de Outlook
- ↳ Despre certificarile Microsoft
- Diverse
- ↳ Discutii libere (Cafenea)
- ALTE FORUMURI ROMANESTI
- ↳ CODEXPERT