0

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 ..

Scott Craner
  • 148,073
  • 10
  • 49
  • 81
  • Try something like `xminuut = Range("J3") + Range("D16")` `Dim remainingMin: remainingMin = Mod(xminuut,60)` for the remaining minutes with a `Worksheetfunction.Rounddown(xminuut/60,0) + Range("B15")+Range("H3")` or what have you for the total hours. Correct me if my logic is flawed. – Notus_Panda Aug 23 '23 at 22:18
  • @Notus_Panda please don't post answers as comments. It even says so in the comments prompt. – teylyn Aug 23 '23 at 23:18
  • Didn't have time to test/write a proper answer att, my apologies @teylyn – Notus_Panda Aug 24 '23 at 07:09

1 Answers1

0

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 :)

Notus_Panda
  • 1,402
  • 1
  • 3
  • 12