Hi jake,
See if this is what you are looking for .
Sub UpdateValues()
'Update this contants to match the sheet names
Const sSHEET_NAME_DAILY As String = "Daily production"
Const sSHEET_NAME_MONTHLY As String = "montly total"
Dim lRow As Long
Dim sFormula As String
' Original Formula without variables (just for clarity)
' =IF(B2="","",SUMIF('Daily production'!B:B,'montly total'!B2,'Daily production'!C:C)'montly total'!C2)
sFormula = "=IF(B2="""",""""," & _
"SUMIF('" & sSHEET_NAME_DAILY & "'!B:B,'" & _
sSHEET_NAME_MONTHLY & "'!B2,'" & _
sSHEET_NAME_DAILY & "'!C:C)+'" & sSHEET_NAME_MONTHLY & "'!C2)"
' Determine the last row for the monthly
With Sheets(sSHEET_NAME_MONTHLY)
lRow = .Cells(Rows.Count, 1).End(xlUp).Row
' Add temporary formula next to it to thet the values
.Range("D2:D" & lRow).Formula = sFormula
' Copy the values to the adjacent column
.Range("D2:D" & lRow).Offset(, -1).Value = .Range("D2:D" & lRow).Value
' Delete the aux column
.Range("D2:D" & lRow).EntireColumn.Delete
End With
End Sub
Thanks
Bookmarks