How can I shortcut all this code into a loop of some kind please.

tungchiu

New Member
Joined
Nov 20, 2005
Messages
34
Hi everybody!
I have columns of data that are generated by formulae inserted by the following code.

Private Sub XtendData()
Dim w As Integer

‘Insert formulae in Col 22
For w = 12 To 200 Step 2
Cells(w, 22).FormulaR1C1 = "=IF(OR(RC[-14]="""", RC[-8] = """"), """", IF(RC[-14] = R8C22, RC[-8], """"))"
Next

‘Insert formulae in Col 23
For w = 12 To 200 Step 2
Cells(w, 23).FormulaR1C1 = "=IF(OR(RC[-15]="""", RC[-9] = """"), """", IF(RC[-15] = R8C23, RC[-9], """"))"
Next

‘Insert formulae in Col 24
For w = 12 To 200 Step 2
Cells(w, b).FormulaR1C1 = "=IF(OR(RC[-16]="""", RC[-10] = """"), """", IF(RC[-16] = R8C24, RC[-10], """"))"
Next

And so on ad infinitum for 25 columns. I know there must be a more efficient way to write this but I can’t figure it out. Can anybody help please as I am facing the prospect of even more columns!
Thanks in advance!
 
In that case, try this
Code:
Sub Insert_Formulas_Every_Second_Row()
  Range("V12:AT12").FormulaR1C1 = "=IF(OR(RC8="""",RC14=""""),"""",IF(RC8=R8C,RC14,""""))"
  Range("V12:AT13").AutoFill Destination:=Range("V12:AT200"), Type:=xlFillDefault
End Sub

Once again Peter, i'm so impressed. I don't quite understand yet how the code works but what a great learning curve! Can't thank you enough for your time & willingness to help. Cheers!
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,215,993
Messages
6,128,175
Members
449,429
Latest member
ianharper68

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