Too lengthy need short code.

NasimAnsari

New Member
Joined
Sep 2, 2020
Messages
19
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello everyone,

I Would need a short VBA code for the below formula.

ActiveCell.FormulaR1C1 = "=R[-10]C[15]/R[-10]C[12]"
Range("C15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[19]/R[-10]C[16]"
Range("D15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[23]/R[-10]C[20]"
Range("E15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[27]/R[-10]C[24]"
Range("F15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[31]/R[-10]C[28]"
Range("G15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[35]/R[-10]C[32]"
Range("H15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[39]/R[-10]C[36]"
Range("I15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[43]/R[-10]C[40]"
Range("J15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[47]/R[-10]C[44]"
Range("K15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[51]/R[-10]C[48]"
Range("L15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[55]/R[-10]C[52]"
Range("M15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[59]/R[-10]C[56]"
Range("N15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[63]/R[-10]C[60]"
Range("O15").Select
ActiveCell.FormulaR1C1 = "=R[-10]C[67]/R[-10]C[64]"
Range("H15").Select


Thank you!

Regards,
Nasim
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
How about
VBA Code:
Sub NasimAnsari()
   Dim i As Long
   For i = 2 To 15
      Cells(15, i).FormulaR1C1 = "=r[-10]c[" & i * 4 + 7 & "]/r[-10]c[" & i * 4 + 4 & "]"
   Next i
End Sub
 
Upvote 0
How about
VBA Code:
Sub NasimAnsari()
   Dim i As Long
   For i = 2 To 15
      Cells(15, i).FormulaR1C1 = "=r[-10]c[" & i * 4 + 7 & "]/r[-10]c[" & i * 4 + 4 & "]"
   Next i
End Sub

Hey Fluff Good morning,

This is second time you help me. Awesome man.

I appreciate your work.

Thank you once again.

Regards,
Nasim
 
Upvote 0
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).

Thanks, Mumps :)

I just added XL2BB Add-ins for macros.

Thank you!

Regards,
Nasim
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0
Hey Fluff Good morning,

This is the second time you help me. Awesome man.

I appreciate your work.

Thank you once again.

Regards,
Nasim

Hello Fluff

I would need your help to add "IFERROR to avoid #DIV/0! error for the below code.

Sub NasimAnsari()
Dim i As Long
For i = 2 To 15
Cells(15, i).FormulaR1C1 = "=r[-10]c[" & i * 4 + 7 & "]/r[-10]c[" & i * 4 + 4 & "]"
Next i
End Sub
 
Upvote 0
How about
VBA Code:
 Cells(15, i).FormulaR1C1 = "=iferror(r[-10]c[" & i * 4 + 7 & "]/r[-10]c[" & i * 4 + 4 & "],"""")"
 
Upvote 0
How about
VBA Code:
 Cells(15, i).FormulaR1C1 = "=iferror(r[-10]c[" & i * 4 + 7 & "]/r[-10]c[" & i * 4 + 4 & "],"""")"

Hey, Fluff thanks for your quick reply.

Code works perfectly :)

Have a good day.

Regards,
Nasim
 
Upvote 0

Forum statistics

Threads
1,214,392
Messages
6,119,254
Members
448,879
Latest member
oksanana

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