How to auto populate row in one table whenever data is entered in another table?

haopyn0916

New Member
Joined
Aug 23, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I am making my own personal budget spreadsheet and trying to update one table automatically whenever a row of data is entered in another table. For example, there are three tables in total, "total budget", "essential budget", and "irregular expense". When data is entered in essential budget table (say 05/09/2021, Rent, 600), I want the entire row being auto populated in the total budget table. Same goes with irregular expense table when row is entered in this table, the total budget table will also auto populate the data that was entered in the irregular expense. Is it possible to do so?

Please see below image

I do not mind to use button, maybe say "update", and whenever I press it the total budget table will be updated whatever are in the essential budget and irregular expense tables. (Also maybe auto the date in the total budget table).
 

Attachments

  • sample.PNG
    sample.PNG
    20.2 KB · Views: 54

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Welcome to the MrExcel board!

For the future, this might help you get faster responses: MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.

Try this Worksheet_Change event code with a copy of your workbook and after updating the table names in the code. Tbl1 should be the name of the main table that holds the combined data.
To implement ..
1. Right click the sheet name tab and choose "View Code".
2. Copy and Paste the code below into the main right hand pane that opens at step 1.
3. Close the Visual Basic window & test.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Const Tbl1 As String = "Table1", Tbl2 As String = "Table2", Tbl3 As String = "Table3" '<- Edit table names
  
  If Not Intersect(Target, Union(Range(Tbl2), Range(Tbl3))) Is Nothing Then
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    With Range(Tbl1)
      .Offset(1).ClearContents
      Range(Tbl2).Copy Destination:=.Cells(2, 1)
      Range(Tbl3).Copy Destination:=.Cells(Range(Tbl2 & "[Date]").Rows.Count + 2, 1)
      With ActiveSheet.ListObjects(Tbl1).Sort
        .SortFields.Clear
        .SortFields.Add2 Key:=Range(Tbl1 & "[[#All],[Date]]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
        .Header = xlYes
        .Apply
      End With
      Do While Application.CountA(.Rows(.Rows.Count)) = 0
        ActiveSheet.ListObjects(Tbl1).ListRows(.Rows.Count).Delete
      Loop
      .Cells(2, .Columns.Count).Resize(Range(Tbl1).Rows.Count - 1).FormulaR1C1 = "=R[-1]C+sum(RC[-2]:RC[-1])"
    End With
    Application.EnableEvents = True
    Application.ScreenUpdating = True
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,391
Members
449,080
Latest member
Armadillos

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