create a loop within a loop

amartino44

Board Regular
Joined
Dec 12, 2012
Messages
56
I created this loop below. Now I need to add code that will divide Range ("C" & i) by the closest cell (going down, not up) with formatting that has an upper line border. How can I add this?

Code:
Sub mil()
For i = 3 To 15
If Range("C" & i).Borders(xlEdgeTop).LineStyle = xlLineStyleNone Then
Else
Range("D" & i) = Range("C" & i) 'Divide by the closest cell with a top border
End If
Next
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Is this what you need?

Code:
Sub mil()
Dim i As Long
For i = 3 To 15
    If Range("C" & i).Borders(xlEdgeTop).LineStyle <> xlLineStyleNone Then Range("D" & i) = Range("D" & i) / Range("C" & i)
Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,206,971
Messages
6,075,925
Members
446,170
Latest member
zzzz02

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top