PDA

View Full Version : insert sum or =+ formula based on value in another column for variable rows



SteveM99
06-20-2019, 08:08 AM
Dear VBAers,

Trying to insert either a sum formula like "=sum(c15+c18+c25) or =+c15+c18+c25 in VBA based on column Q which identities the variable rows with text as "TOT"

This is my code and I admit I am challenged by this. Not sure how to code the variable part. I do not want a sumifs formula because I need to delete column Q after inserting the formula.

With Worksheets("REPORT")

Dim Rws3 As Long, Rng3 As Range, c3 As Range
Rws3 = Cells(Rows.Count, "Q").End(xlUp).Row
Set Rng3 = Range(Cells(2, "Q"), Cells(Rws3, "Q"))
For Each c3 In Rng3.Cells
If c3 = "INS" Then c3.Offset(0, -14).Formula = "=sum(C" & ?????????? & ")"
Next c3


End With

Leith Ross
06-21-2019, 03:22 PM
Hello SteveM99,

Can you post the worksheet for reference? Ideally, posting the complete workbook would be best.