Pretendo procurar linha a linha dentro da coluna P:P
um número inferior ou igual a 200 e executar um comando. Se for superior a 200 executar outro. Os valores estão definidos assim 0.0
.
If .Value =< 200 Then
ActiveCell.FormulaR1C1 = "=RC[-5]*1.69*(1+30%)"
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("U2").AutoFill Destination:=Range("U2:U" & Lastrow)
ElseIf .Value > 200 Then
ActiveCell.FormulaR1C1 = "=RC[-5]*1.69*(1+40%)"
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("U2").AutoFill Destination:=Range("U2:U" & Lastrow)
End If
RESPOSTA:
Sub teste()
Dim rng As Range
Set rng = Range("P1:P300") 'Se colocar P:P vai até à última linha
For Each Row In rng.Rows
If Row.Value < "200" Then
Range("U2").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*1.69*(1+30%)"
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("U2").AutoFill Destination:=Range("U2:U" & Lastrow)
Selection.NumberFormat = "0"
ElseIf Row.Value >= "200" Then
Range("U2").Select
ActiveCell.FormulaR1C1 = "=RC[-5]*1.69*(1+40%)"
ultima_linhaLastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("U2").AutoFill Destination:=Range("U2:U" & ultima_linhaLastrow)
Selection.NumberFormat = "0"
End for
End If
Next Row
End Sub