PDA

View Full Version : Error - manipulate dates in VBA



gohan123
06-06-2007, 12:59 PM
Hi,

I,m trying input a value in a cell depend on a value in other cell. But I need to calculated how much time pass from now to that situation and input a information. :banghead:
In this c?digo there is what a need:


Private Sub Classificar_backlog()
Dim i As Variant
Dim Backlog As Variant
Dim resol As Variant
Dim result As Variant

For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row()
'take a value in a cell - this value is a date like 6/06/2007 14:12:55
Backlog = Cells(i, "D").Value

resol = Now()

'this value must be insert like 1,20 or 13,0, etc... in column H
Cells(i, "H").Value = (resol - Backlog)

Select Case Cells(i, "H").Value
Case Is <= 2, 0
Cells(i, "E").Value = "Inicial"

Case Is > 2, 0 >= 4, 0 'if between 2,0 and 4,0
Cells(i, "E").Value = "Meio"

Case Is < 4, 0
Cells(i, "E").Value = "Fim"
End Select
Next i
End Sub


Somebody help me, please....

Tks,

Gohan

Edited 8-Jun-07 by geekgirlau. Reason: insert line breaks

Ebrow
06-07-2007, 05:48 AM
mmm. Not really sure what you are asking here:

You can format a date with the format command.



myValue = resol - backlog
Cells(i,"H").value = format(myValue, "ddmmyyyy hh:mm:ss")


This would put the result in the format of "ddmmyyyy hh:mm:ss"

You can change these letters around to match your prefered format.

Are you doing days and hours you could do "dd,hh"

Am i on track to what you are looking for?

mdmackillop
06-07-2007, 09:50 AM
Cells(i, "H").Value = (resol - Backlog) 'this value must be insert
Cells(i, "H").NumberFormat = "[h]:mm"

gohan123
06-12-2007, 05:20 AM
You are the best,

It's work know.

Tks a tol


Cells(i, "H").Value = (resol - Backlog) 'this value must be insert
Cells(i, "H").NumberFormat = "[h]:mm"