Your code does not produce a "time" for me, it produces a Date. Therefore the problem is likely to be either with your data or your environment.
I can get it to output an integer if I put
into a cell that is formatted as
or I can get it to display as a time if I change the format of the cell to
. I can also get it as a Time if the Range G2 contains a time and E2 < 779 and B2 > 391
Impossible to tell what you are doing as your code discards the results and does nothing with them. I can only suggest that you use the debugging tools available (e.g. Watch window, Immediate window) to work out what is going wrong.
Other things that may be causing you problems/you could be tidier with:-
1. See this code
Restante = Coutas
I suspect that is meant to match the variable you have declared and should read
Restante = Cuotas
You can avoid runtime errors like that by always using
at the start of your modules. You can get the IDE to do this by default by ensuring Tools, Options, Editor, Require Variable Declaration is ticked.
2. You have not declared the variables
meaning they are all of type
. You have declared
as a String when it is quite clearly meant to be an Integer. VBA is quite forgiving but I have found through bitter experience that it is best to explicitly state which type (and make sure it is the correct type!) throughout any calculations, and not to assume defaults either.
3. Your hard-coded value
Hoy = #6/28/2022#
assumes the date is in US format - it is better practice to use less ambiguous date formats e.g. use
Hoy = #2022-06-28#
Incidentally, and this is probably no more than personal preference, I dislike the use of # to define dates in VBA and would use
Hoy = CDate("2022-06-28")
Hoy = DateSerial(Year:=2022, Month:=6, Day:=28)
Hoy = DateValue("2022-06-28")
4. You create a variable
, assign it a value of "m" but then don't use it in any of your calculations. Code Tidily and many potential errors simply go away!