Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding records to a table with code

Status
Not open for further replies.

laguna92651

Programmer
Apr 4, 2012
7
US
I am adding multiple records at one time to a table from a another worksheet with code. Even though the records are added to the bottom of the table they do not seem to be part of the table structure. Any formulas that are part of the table are not implemented in the new records. If I have a pivot table already created before adding the new records, and do a refresh of the pivot table the new records are not reflected in the refreshed results. If I add the pivot table after the new records are added, the pivot table totals are correct. Any ideas on how can include the new records in the table, table6.

Code:
Sub MoveRecord() 

        Dim Increment As Integer 'looping variable 
           Dim WSF As Worksheet ' Invoice worksheet 
           Dim WSD As Worksheet ' SalesData worksheet 
           Set WSF = Worksheets("Invoice") 
           Set WSD = Worksheets("SalesData") 
           NextRow = WSD.Cells(Rows.Count, 2).End(xlUp).Row + 1 

        For Increment = 19 To 34 
           If WSF.Cells(Increment, 3) <> "" Then 

           WSD.Cells(NextRow, 1).Resize(1, 14).Value = Array([D4], [F4], [F4], [F3], [A16], [B16], [c9],
           Cells(Increment, 3), Cells(Increment, 4), Cells(Increment, 11), Cells(Increment, 2), 
           Cells(Increment, 12), Cells(Increment, 13), Cells(Increment, 14))

        NextRow = WSD.Cells(Rows.Count, 2).End(xlUp).Row + 1 

        End If 

        Next Increment
End Sub
 
In the pivot table, select the change data source option and extend the table. No macro necessary.
 
Instead of a table name, I've change the source to a named range, with extra rolls added. I can now update the pivot table but the formulas in table don't update in the new records. I use calculations in some "helper cells" to automatically extract unique data to other worksheets. For example automatically update a Customer list. thanks for the help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top