Loop in a Range

A

aksel børve

I am trying to make a loop that calculate each cell to the right of the
"RngMdDp1"-range, based on the value in cell "I3" and "RngMdDp1" . The cells
in "RngMdDp1" gets higher values for each cells, so at one cell there sould
be a breaking point, and the formula would be changed.
can anyone se whats wrong with the macro?
Sub DrillPipe1()
For Each c In Range("RngMdDp1")
If c.Value < ("I3") Then c.Offset(0, 1).FormulaR1C1 =
"=(RC[-1]*RC[-2])" Else c.Offset(0, 1).FormulaR1C1 = "=(RC[-1])"
Next c
End Sub
 
T

Tom Ogilvy

Sub DrillPipe1()
Dim c as Range
For Each c In Range("RngMdDp1")
If c.Value < Range("I3") Then
c.Offset(0, 1).FormulaR1C1 = _
"=(RC[-1]*RC[-2])"
Else
c.Offset(0, 1).FormulaR1C1 = "=(RC[-1])"
End if
Next c
End Sub
 
A

Aksel Børve

Thanks for your solutionOgilvy! And thanks to all the programmers who has
helpt me with my questions.

My problem is that I want to calculate every cell to the right from
"RngMdDp1", based on the value on every cell in "RngMdDp1"That meens
cells(O2:O115). compare to the value in cell (I3)

Tom Ogilvy said:
Sub DrillPipe1()
Dim c as Range
For Each c In Range("RngMdDp1")
If c.Value < Range("I3") Then
c.Offset(0, 1).FormulaR1C1 = _
"=(RC[-1]*RC[-2])"
Else
c.Offset(0, 1).FormulaR1C1 = "=(RC[-1])"
End if
Next c
End Sub

--
Regards,
Tom Ogilvy

aksel børve said:
I am trying to make a loop that calculate each cell to the right of the
"RngMdDp1"-range, based on the value in cell "I3" and "RngMdDp1" . The cells
in "RngMdDp1" gets higher values for each cells, so at one cell there sould
be a breaking point, and the formula would be changed.
can anyone se whats wrong with the macro?
Sub DrillPipe1()
For Each c In Range("RngMdDp1")
If c.Value < ("I3") Then c.Offset(0, 1).FormulaR1C1 =
"=(RC[-1]*RC[-2])" Else c.Offset(0, 1).FormulaR1C1 = "=(RC[-1])"
Next c
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top