excelsumintegerminutecombining-marks

Is there anyway for combining minutes and hours here?


enter image description here

So in the image what i want is when you click the button there, the 30 minutes are summed up in the top, but it should become 47 hours and 10 minutes.

Now it becomes 46 hours and 70 min ...

Is there anyway for this to work properly?

My code now (still beginning):

Dim xuur As Integer
Dim xminuut As Integer

Dim dag As String
Dim naam As String

xuur = Range("D15")
xminuut = Range("D16")

dag = Range("B15")
naam = Range("C12")


Dim arve As String
arve = "Arne Verdru"


If naam = arve Then
    Range("H3") = WorksheetFunction.Sum(Range("H3"), xuur)
    Range("J3") = WorksheetFunction.Sum(Range("J3"), xminuut)
    Range("D15") = 0
    Range("D16") = 0
Else
MsgBox "Wrong name."
    
End If

still a newbie at coding in excel so i have not much tried something, it seems impossible ..


Solution

  • Adding all minutes together will of course lead you to the 70 minutes, you'll need to adjust the logic a bit to accommodate the hours as well:

    Sub test()
        Dim xuur As Integer
        Dim xminuut As Integer
        Dim dag As String
        Dim naam As String
        
        xuur = Range("D15") + Range("H3") 'you don't need WorksheetFunction.Sum to add something together in VBA
        xminuut = Range("J3") + Range("D16")
        dag = Range("B15")
        naam = Range("C12")
        
        Dim arve As String
        arve = "Arne Verdru"
        
        Dim remainingMin As Long
        If naam = arve Then
            remainingMin = xminuut Mod 60 'basically what's left over if you divide xminuut by 60, in Dutch known as "rest"
            Range("H3") = WorksheetFunction.RoundDown(xminuut / 60, 0) + xuur 'how often 60 fits in xminuut added with the known total hours
            Range("J3") = remainingMin
            Range("D15") = 0
            Range("D16") = 0
        Else
            MsgBox "Wrong name."
        End If
    End Sub 
    

    Hope the comments in code are enough to understand the functions :)