B
bst
I have googled and searched this group and have not found exactly what i
am looking for. everything i have seen is for performing functions in
the worksheet and not in vba code.
i'll set up the prolbem, explain what i need, and give you what i have
come up with so far.
i have two columns with time data. i want the third column to show the
difference between the time. so if one 13:30 and the other is 14:00 i
want the 3rd column to show :30. or if one is 14:00 and the other is
13:30 i want the 3rd column to show :30
A B C
13:30 14:00 :30
14:00 13:30 :30
the all cells are formatted as general. the code snippets below are for
excel2000.
If .Cells(row, colSchedule).Value > .Cells(row, colActual).Value Then
.Cells(row, colVariance).Value = .Cells(row, colSchedule).Value - _
.Cells(row, colActual).Value
Range(.Cells(row, colVariance)).NumberFormat = "hh:mm"
Else
.Cells(row, colVariance).Value = .Cells(row, colActual).Value - _
.Cells(row, colSchedule).Value
Range(.Cells(row, colVariance)).NumberFormat = "hh:mm"
End if
i have also attempted using Range(.cells(row,colSchedule).value etc....
in both attempts the comparison works fine (which boggles my mind),
however the cell assignment/mathematic operation fails with a mismatch
object error.
all cells formatted as general. i don't know if that is the problem, but
i doubt it since if i do this in the sheet, eg =B1-A1, i get no problem.
The code does not make it to the Range......NumberFormat so i have no
idea if that will work or not.
I do not think the builtin Time function(time(h,m,s) will work since i
cant seperate the information by hour.minutes. i have read how excel
stores time data, but i do not (hope not) think that applies.
what this is not is a payroll sheet or some sort of userform. based on
the if statements above some other things get processed and sorted out,
i have not included them for brevity.
there will also be a future comparison based on the result of the
calculation to the effect of if it is > 30 then something happens, if it
< 30 something else happens.
i hope this is clear.
TIA
bst
am looking for. everything i have seen is for performing functions in
the worksheet and not in vba code.
i'll set up the prolbem, explain what i need, and give you what i have
come up with so far.
i have two columns with time data. i want the third column to show the
difference between the time. so if one 13:30 and the other is 14:00 i
want the 3rd column to show :30. or if one is 14:00 and the other is
13:30 i want the 3rd column to show :30
A B C
13:30 14:00 :30
14:00 13:30 :30
the all cells are formatted as general. the code snippets below are for
excel2000.
If .Cells(row, colSchedule).Value > .Cells(row, colActual).Value Then
.Cells(row, colVariance).Value = .Cells(row, colSchedule).Value - _
.Cells(row, colActual).Value
Range(.Cells(row, colVariance)).NumberFormat = "hh:mm"
Else
.Cells(row, colVariance).Value = .Cells(row, colActual).Value - _
.Cells(row, colSchedule).Value
Range(.Cells(row, colVariance)).NumberFormat = "hh:mm"
End if
i have also attempted using Range(.cells(row,colSchedule).value etc....
in both attempts the comparison works fine (which boggles my mind),
however the cell assignment/mathematic operation fails with a mismatch
object error.
all cells formatted as general. i don't know if that is the problem, but
i doubt it since if i do this in the sheet, eg =B1-A1, i get no problem.
The code does not make it to the Range......NumberFormat so i have no
idea if that will work or not.
I do not think the builtin Time function(time(h,m,s) will work since i
cant seperate the information by hour.minutes. i have read how excel
stores time data, but i do not (hope not) think that applies.
what this is not is a payroll sheet or some sort of userform. based on
the if statements above some other things get processed and sorted out,
i have not included them for brevity.
there will also be a future comparison based on the result of the
calculation to the effect of if it is > 30 then something happens, if it
< 30 something else happens.
i hope this is clear.
TIA
bst