title: Excel 365 VBA for hours and minutes format
body: <p>I'm working on a simple Excel file with some worksheets where in every one I've report hours and minutes of work. I want to show it like 313:32 that is 313 hours and 32 minutes, to do that I'm using a custom format <code>[h]:mm</code></p>
  <p>To facilitate the workers that use Excel very little, I have thought to create some vba code, so that they could insert also not only the minutes, besides the classical format <code>[h]:mm</code>, so they can also insert value in hours and minutes.
  I report some example data that I want to have.
  What I insert -&gt; what I want that are printed inside the cell</p>
  <ul>
  <li>1 -&gt; 0:01</li>
  <li>2 -&gt; 0:02</li>
  <li>3 -&gt; 0:03</li>
  <li>65 -&gt; 1:05</li>
  <li>23:33 -&gt; 23:33</li>
  <li>24:00 -&gt; 24:00</li>
  <li>24:01 -&gt; 24:01</li>
  </ul>
  <p>Then I formatted every cell that can contain a time value in <code>[h]:mm</code> and I wrote this code</p>
  <pre><code>Public Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  On Error GoTo bm_Safe_Exit
      With Sh
          If IsNumeric(Target) = True And Target.NumberFormat = &quot;[h]:mm&quot; Then
  
              If Int(Target.Value) / Target.Value = 1 Then
                  Debug.Print &quot;Integer -&gt; &quot; &amp; Target.Value
                  Application.EnableEvents = False
                  Target.Value = Target.Value / 1440
                  Application.EnableEvents = True
                  Exit Sub
              End If
  
              Debug.Print &quot;Other value -&gt; &quot; &amp; Target.Value
          End If
      End With
  bm_Safe_Exit:
      Application.EnableEvents = True
  End Sub
  </code></pre>
  <p>The code works well enough, but it errs when I enter 24:00 and its multiples, 48:00, 72:00 ...
  This because the cell are formatted <code>[h]:mm</code> so 24:00 became 1 before the vba code execution!</p>
  <p>I tried to correct the code, and the funny fact is that when I correct the 24:00, so 24:00 remain 24:00 and not 00:24, the problem switch to 1 that became 24:00 instead 00:01</p>
  <p>My first idea was to &quot;force&quot; the vba code execution before the cell format, but I don't know if it is possible.
  I know that seems a stupid question, but I really don't know if it is possible and how to fix it.</p>
  <p>Any idea will be much appreciated</p>