Here's my dilemma:
I have followed the add new row/cell formula from Ron de Bruin and it works splendidly; however, I am taking the values entered in the new cells and using them in calculations ... which are also in new cells added. I'll past the code I'm referencing below:
rng.Parent.Cells(LastRow + 1, LastCol + 2).Value = spm
rng.Cells(LastRow + 1, LastCol + 2).Borders(xlDiagonalDown).LineStyle = xlNone
rng.Cells(LastRow + 1, LastCol + 2).Borders(xlDiagonalUp).LineStyle = xlNone
With rng.Cells(LastRow + 1, LastCol + 2).Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With rng.Cells(LastRow + 1, LastCol + 2).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With rng.Cells(LastRow + 1, LastCol + 2).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With rng.Cells(LastRow + 1, LastCol + 2).Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
rng.Cells(LastRow + 1, LastCol + 2).Borders(xlInsideVertical).LineStyle = xlNone
rng.Cells(LastRow + 1, LastCol + 2).Borders(xlInsideHorizontal).LineStyle = xlNone
With rng.Cells(LastRow + 1, LastCol + 2)
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
rng.Parent.Cells(LastRow + 1, LastCol + 3).Locked = False
Range("K8").Value = tsqs
Range("L8").Value = spm
'Calculate value for Man Hours per Item
rng.Parent.Cells(LastRow + 1, LastCol + 3).Formula = <<still working on this bit>>
So, basically what I am wondering is: 1. How would I add a formula to a cell (new cell in column 3 & 4) which uses the value of the two newly created cells?
Basic Layout:
Row 16, Column A (Preset Text input) | Column B (InputBox generates cell value) | Column C (InputBox generates cell value) | Column D (formula to calculate B * C) | Column E (formula to calculate D * B)
I can get formulas to calculate through VBA, that's not the issue; my issue is that if a user changes the value in any of the newly created cells in Columns B/C, how do I / can I update the formula in the newly created cells in Columns D & E?
I was thinking of using Worksheet.Calculate but I'm not certain that will work on the VBA calculations.
I can post the full Sub() to view if that is needed.
Cell.Formula = "= B3 * C3"
or you can mark the calculating function as volatile. – David Rushton