I am starting to learn VBA. On this For/Next loop, I am stumped by one line of code:

If myValue > 400 Then Range("F" & i).Value = myValue + 10

I get the first part: If myValue > 400 Then

but I do not understand the second part: Range("F" & i).Value = myValue + 10

Why must I use Range("F" & i).Value = on the left-hand side and the variable on the right?

I have tried

If myValue > 400 Then myValue = myValue + 10

but it does not work (nothing changes). Why doesn't it work?

If myValue = 560, then I would translate this to:

If 560 > 400 Then 560 = 560 + 10

But nothing changes on screen; yet, if I use

If myValue > 400 Then

it works fine.

Why?

Dim LastRow As Long

Dim myValue As Double

Const StartRow As Byte = 10

LastRow = Range("A" & StartRow).End(xlDown).Row

For i = StartRow To LastRow

myValue = Range("F" & i).Value

If myValue > 400 Then Range("F" & i).Value = myValue + 10

Next i

End Sub

If myValue > 400 Then Range("F" & i).Value = myValue + 10

I get the first part: If myValue > 400 Then

but I do not understand the second part: Range("F" & i).Value = myValue + 10

Why must I use Range("F" & i).Value = on the left-hand side and the variable on the right?

I have tried

If myValue > 400 Then myValue = myValue + 10

but it does not work (nothing changes). Why doesn't it work?

If myValue = 560, then I would translate this to:

If 560 > 400 Then 560 = 560 + 10

But nothing changes on screen; yet, if I use

If myValue > 400 Then

**Range("F" & i).Value**= myValue + 10it works fine.

Why?

**Sub Simple_For_Next()Dim i As Long**

Here's the code:

Here's the code:

Dim LastRow As Long

Dim myValue As Double

Const StartRow As Byte = 10

LastRow = Range("A" & StartRow).End(xlDown).Row

For i = StartRow To LastRow

myValue = Range("F" & i).Value

If myValue > 400 Then Range("F" & i).Value = myValue + 10

Next i

End Sub

**Excel 2016 (Windows) 64 bit**F | |
---|---|

9 | Quantity |

10 | 130 |

11 | 570 |

12 | 130 |

13 | 760 |

14 | 930 |

Sheet: ForNext |

Last edited: