paste formula every 4th row dependin on value in Col A

r333dma

New Member
Joined
Jan 29, 2017
Messages
4
I’m an occasional user of VBA so knowledge very limited.
I have worksheet columns A-G starting at row 4, cell H7contains a formula based on D4 and D7. I need some VBA which identifies whenCol A has a value in A11, A15, etc (every 4th row) and then copiesthe formula from H7 to every 4th row in Col H. Each time the formulais pasted it needs to look at Col D (current row) and Col D (current row -3). Ifthere is no value in Col A then nothing would happen.
Any help with this would be appreciated.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
you didnt provide the formula.

Code:
Public Sub MakeFormulae()
Dim iRows As Long
Dim vFormu


vFormu = "R[-1]+c[2]"


Range("A4").Select
iRows = UsedRange.Rows.Count


For r = 4 To iRows Step 4
   ActiveCell.Offset(4, 0).Select
      'check col H
   If ActiveCell.Value <> "" Then ActiveCell.Offset(0, 7).FormulaR1C1 = "=" & vFormu
Next
End Sub
 
Upvote 0
Hi Ranman256

I have added the code but get a run time error object required at iRows = UsedRange.Rows.Count I added my formula which is D7-D4 and still got the error.

any ideas.

regards

Mark
 
Upvote 0
How about
Code:
Sub AddFormula()
   Dim i As Long
   
   For i = 11 To Range("A:G").find("*", , xlValues, , xlRows, xlPrevious, False, , False).Row Step 4
      If Range("A" & i) <> "" Then Range("H" & i).FormulaR1C1 = "=rc4-r[-3]c4"
   Next
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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