Hi there, I have a userform that adds a new row to the table "totalTable" on the worksheet "Totals" that also adds a new row to different worksheet table called Breakdown. When it adds a new row to the Totals it adds formulas to certain columns that reads off of the Breakdown worksheet. The formula searches for values in the rows that have the same first name and surname.
It works, however my issue is when I add a new row, the formula with the new row overwrites all the previous rows formulas. So they are looking for the same name.
I hope this makes sense. Please see my code below. Any assistance is appreciated.
It works, however my issue is when I add a new row, the formula with the new row overwrites all the previous rows formulas. So they are looking for the same name.
I hope this makes sense. Please see my code below. Any assistance is appreciated.
VBA Code:
Private Sub SubmitButton_Click()
'Submit button
Dim wso As Worksheet
Dim newrowo As ListRow
Set wso = ThisWorkbook.Worksheets("Breakdown")
Set wso2 = ThisWorkbook.Worksheets("Totals")
Set newrowo = wso.ListObjects("breakdownTable").ListRows.Add
Set newrowo2 = wso2.ListObjects("totalTable").ListRows.Add
With newrowo
.Range(1) = SurnameTBox.Value
.Range(2) = FnameTBox.Value
.Range(3) = YearTBox.Value
.Range(4) = 0
.Range(5) = 0
.Range(6) = 0
.Range(7) = 0
.Range(8) = 0
.Range(9) = 0
With newrowo2
.Range(1) = SurnameTBox.Value
.Range(2) = FnameTBox.Value
.Range(3).Formula = "=SUMIFS(Breakdown!D:D, Breakdown!A:A,""" & .Range(1) & """, Breakdown!B:B,""" & .Range(2) & """)"
.Range(4).Formula = "=SUMIFS(Breakdown!E:E, Breakdown!A:A,""" & .Range(1) & """, Breakdown!B:B,""" & .Range(2) & """)"
.Range(5).Formula = "=SUMIFS(Breakdown!F:F, Breakdown!A:A,""" & .Range(1) & """, Breakdown!B:B,""" & .Range(2) & """)"
.Range(6).Formula = "=SUMIFS(Breakdown!G:G, Breakdown!A:A,""" & .Range(1) & """, Breakdown!B:B,""" & .Range(2) & """)"
.Range(7).Formula = "=SUMIFS(Breakdown!H:H, Breakdown!A:A,""" & .Range(1) & """, Breakdown!B:B,""" & .Range(2) & """)"
.Range(8).Formula = "=SUMIFS(Breakdown!I:I, Breakdown!A:A,""" & .Range(1) & """, Breakdown!B:B,""" & .Range(2) & """)"
.Range(9) = YearTBox.Value
End With
Unload Me
SubmitScreen.Show
End With
End Sub