VBA loop amount of times depending on value in cell

MrSak87

New Member
Joined
Jan 8, 2015
Messages
44
Hello experts

I have a section of code which goes like this.

For i = 3 To 27
Range("co3").Select
ActiveCell.FormulaR1C1 = _
"=CORREL(RC[-6]:R[17127]C[-6],RC[-5]:R[17127]C[-5])"
Selection.Copy
Range("cp" & Rows.Count).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("cj3").Select
Selection.Delete Shift:=xlUp

Next i

The code (probably messy for you guys) works perfectly and does what I want it to do. However depending on certain conditions of the data I'm using I have to manually change the amount it loops. I have this loop 6 times for 3 different axis so it is quite annoying and time consuming.

Is there a way I can change that number "27" to represent a call value on my work sheet.

For example in cell "A1" I had the value 10 it would just do it 10 times?

Thank you for any help
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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