Userform adding new row to table with specific formulas is overwriting previous formulas

Megg

New Member
Joined
Nov 5, 2023
Messages
11
Office Version
  1. 365
Platform
  1. Windows
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.

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
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try adding this line at the beginning of the procedure:
VBA Code:
Application.AutoCorrect.AutoFillFormulasInLists = False
Artik
 
Upvote 1
Solution

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top