ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Code returns TRUE instead of value (https://www.excelbanter.com/excel-discussion-misc-queries/108549-code-returns-true-instead-value.html)

loren.pottinger

Code returns TRUE instead of value
 
Essentially what I am trying to do is this:

I am trying to calculate depreciation.

I use the DateAdd function to add x number of months(Cell "F & Row that
is active") to the acquisition date(Cell "H & Row that is active" of
an asset.

If the sum of those dates is greater than the End of life (Cell "I &
Row that is active") of that asset then there is a payment for that
month and the value in Range("K" & Row) is place in the active cell
until the entire cell range from M7 to AC63 is filled.

If the sum of those dates is not greater the End of life (Cell "I & Row
that is active") of that asset then a value of zero is place in that
cell.

In either case the value in (Cell "F & Row that is active")
decremented by 1 for the next time the loop is run.

It runs, and the range is being filled, but there is not supposed to be
a payment for every cell in the range. There are no zeros for when the
condition is false.

Additionally, the entire Column "M" only has the word TRUE and not a
numerical value. My macro is as follows. Please help.

Sub Fill()

Dim TestDate As Date
Dim Col As Integer
Dim Row As Long

For Col = 13 To 29
For Row = 7 To 63

TestDate = DateAdd("m", Range("F" & Row), _
Range("H" & Row))

If TestDate < Range("I" & Row) Then

Range("K" & Row).Copy
Cells(Row, Col) = Range("K" & Row)
Range("F" & Row).Value = Range("F" & Row).Value - 1

Else
Cells(Row, Col) = ActiveCell.Value = 0
Range("F" & Row).Value = Range("F" & Row).Value - 1
End If

Next Row
Next Col
End Sub


Gary''s Student

Code returns TRUE instead of value
 
Cells(Row, Col) = ActiveCell.Value = 0
says that if ActiveCell.Value equals 0, then set Cells(Row, Col).Value = True
because (ActiveCell.Value=0) is a Boolean
--
Gary's Student


"loren.pottinger" wrote:

Essentially what I am trying to do is this:

I am trying to calculate depreciation.

I use the DateAdd function to add x number of months(Cell "F & Row that
is active") to the acquisition date(Cell "H & Row that is active" of
an asset.

If the sum of those dates is greater than the End of life (Cell "I &
Row that is active") of that asset then there is a payment for that
month and the value in Range("K" & Row) is place in the active cell
until the entire cell range from M7 to AC63 is filled.

If the sum of those dates is not greater the End of life (Cell "I & Row
that is active") of that asset then a value of zero is place in that
cell.

In either case the value in (Cell "F & Row that is active")
decremented by 1 for the next time the loop is run.

It runs, and the range is being filled, but there is not supposed to be
a payment for every cell in the range. There are no zeros for when the
condition is false.

Additionally, the entire Column "M" only has the word TRUE and not a
numerical value. My macro is as follows. Please help.

Sub Fill()

Dim TestDate As Date
Dim Col As Integer
Dim Row As Long

For Col = 13 To 29
For Row = 7 To 63

TestDate = DateAdd("m", Range("F" & Row), _
Range("H" & Row))

If TestDate < Range("I" & Row) Then

Range("K" & Row).Copy
Cells(Row, Col) = Range("K" & Row)
Range("F" & Row).Value = Range("F" & Row).Value - 1

Else
Cells(Row, Col) = ActiveCell.Value = 0
Range("F" & Row).Value = Range("F" & Row).Value - 1
End If

Next Row
Next Col
End Sub



Dave Peterson

Code returns TRUE instead of value
 
You have several replies to your several posts.

Please don't multipost.

"loren.pottinger" wrote:

Essentially what I am trying to do is this:

I am trying to calculate depreciation.

I use the DateAdd function to add x number of months(Cell "F & Row that
is active") to the acquisition date(Cell "H & Row that is active" of
an asset.

If the sum of those dates is greater than the End of life (Cell "I &
Row that is active") of that asset then there is a payment for that
month and the value in Range("K" & Row) is place in the active cell
until the entire cell range from M7 to AC63 is filled.

If the sum of those dates is not greater the End of life (Cell "I & Row
that is active") of that asset then a value of zero is place in that
cell.

In either case the value in (Cell "F & Row that is active")
decremented by 1 for the next time the loop is run.

It runs, and the range is being filled, but there is not supposed to be
a payment for every cell in the range. There are no zeros for when the
condition is false.

Additionally, the entire Column "M" only has the word TRUE and not a
numerical value. My macro is as follows. Please help.

Sub Fill()

Dim TestDate As Date
Dim Col As Integer
Dim Row As Long

For Col = 13 To 29
For Row = 7 To 63

TestDate = DateAdd("m", Range("F" & Row), _
Range("H" & Row))

If TestDate < Range("I" & Row) Then

Range("K" & Row).Copy
Cells(Row, Col) = Range("K" & Row)
Range("F" & Row).Value = Range("F" & Row).Value - 1

Else
Cells(Row, Col) = ActiveCell.Value = 0
Range("F" & Row).Value = Range("F" & Row).Value - 1
End If

Next Row
Next Col
End Sub


--

Dave Peterson


All times are GMT +1. The time now is 08:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com