vba to insert formula every other cell

jordanburch

Active Member
Joined
Jun 10, 2016
Messages
443
Office Version
  1. 2016
Hey guys,

im trying to get the vba code to insert every other cell

basically starting with cell r3 it would insert this function

=IF(Q2="pride Mobility products Corporation",O2*-0.02,IF(Q2="Quantum rehab",O2*-0.02,IF(Q2="Drive Medical",O2*-0.01,0)))

then it would insert it into r5 r7 r9 r11 r13 until there is no more data in any row. This would need to be dynamic as it would change each result, so when it inserts into r5 it should look like this

=IF(Q4="pride Mobility products Corporation",O4*-0.02,IF(Q4="Quantum rehab",O4*-0.02,IF(Q4="Drive Medical",O4*-0.01,0)))

and so and and so forth. Please let me know your thoughts.

Thanks!

Jordan
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Turn on your Macro Recorder, and record yourself entering the formula manually into cell R3.
This will record how the formula is to be entered, and by default, Excel VBA will use relative (R1C1) referencing.
Then, you can place it in a loop like this:
Code:
    Dim myRow As Long
    
    myRow = 3
    Do Until Cells(myRow - 1, "Q") = ""
        Cells(myRow, "R").FormulaR1C1 = "[I]your record formula here[/I]"
        myRow = myRow + 2
    Loop
 
Upvote 0
Works like a charm! thank you sir!

Jordan










Turn on your Macro Recorder, and record yourself entering the formula manually into cell R3.
This will record how the formula is to be entered, and by default, Excel VBA will use relative (R1C1) referencing.
Then, you can place it in a loop like this:
Code:
    Dim myRow As Long
    
    myRow = 3
    Do Until Cells(myRow - 1, "Q") = ""
        Cells(myRow, "R").FormulaR1C1 = "[I]your record formula here[/I]"
        myRow = myRow + 2
    Loop
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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