Tom
Tom

Reputation: 47

Applying formula every 3rd row in a different column VBA Macro

I have this formula =SUM(D4*(K4/100)) I would like to apply in Column M starting at M4 all the way down to last row of data used. How would I achieve this using a macro?

Upvotes: 1

Views: 1218

Answers (1)

Amorpheuses
Amorpheuses

Reputation: 1423

This should do that for you:

Option Explicit

Sub Every3rdRow()
  Dim sht As Worksheet
  Set sht = Worksheets("Sheet1")
  Dim lastRow As Integer
  With sht
    lastRow = .Cells(.Rows.Count, "D").End(xlUp).Row
    Dim r As Integer
    For r = 4 To lastRow Step 3
       .Cells(r, "M").Formula = "=sum(D" & r & "*(K" & r & "/100))"
    Next
  End With
End Sub

Upvotes: 2

Related Questions