ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If-Then-Else Statement (https://www.excelbanter.com/excel-programming/372208-if-then-else-statement.html)

loren.pottinger

If-Then-Else Statement
 
It is not executing my If-Then-Else statement.
It seems the only statement being executed is: Cells(Row, Col).Value =
Range("K" & Row) and I only want it to do that if the condition is
true, and put a 0 in each cell in the range if it is false. Can someone


please look at my code and help me to get it to execute the
If-Then-Else statement. Thank you. Updated code as follows:


Sub Fill()


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


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


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


If TestDate < Range("I" & Row).Value Then
Cells(Row, Col).Value = Range("K" & Row)
Range("F" & Row).Value = Range("F" & Row).Value - 1



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



End If
End With


Next Row
Next Col
End Sub


Dave Peterson

If-Then-Else Statement
 
Another multipost.

"loren.pottinger" wrote:

It is not executing my If-Then-Else statement.
It seems the only statement being executed is: Cells(Row, Col).Value =
Range("K" & Row) and I only want it to do that if the condition is
true, and put a 0 in each cell in the range if it is false. Can someone

please look at my code and help me to get it to execute the
If-Then-Else statement. Thank you. Updated code as follows:

Sub Fill()

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

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

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

If TestDate < Range("I" & Row).Value Then
Cells(Row, Col).Value = Range("K" & Row)
Range("F" & Row).Value = Range("F" & Row).Value - 1

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

End If
End With

Next Row
Next Col
End Sub


--

Dave Peterson

Dave Peterson

If-Then-Else Statement
 
Loren asks that anyone respond in .misc.

Dave Peterson wrote:

Another multipost.

"loren.pottinger" wrote:

It is not executing my If-Then-Else statement.
It seems the only statement being executed is: Cells(Row, Col).Value =
Range("K" & Row) and I only want it to do that if the condition is
true, and put a 0 in each cell in the range if it is false. Can someone

please look at my code and help me to get it to execute the
If-Then-Else statement. Thank you. Updated code as follows:

Sub Fill()

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

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

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

If TestDate < Range("I" & Row).Value Then
Cells(Row, Col).Value = Range("K" & Row)
Range("F" & Row).Value = Range("F" & Row).Value - 1

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

End If
End With

Next Row
Next Col
End Sub


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 03:18 AM.

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