Forum Discussion

neurtron1080's avatar
neurtron1080
Copper Contributor
Aug 09, 2022
Solved

How to make a macro that updates a summary table with inputs

Hello All,   I am attempting to make a macro that can take inputs from one sheet and update a table on another sheet accordingly.   For example, say I run apple orchards and am attempting to keep...
  • OliverScheurich's avatar
    Aug 09, 2022

    neurtron1080 

    Sub apples()
    
    Dim i As Long
    Dim j As Long
    Dim k As Long
    Dim m As Long
    Dim n As Long
    
    For i = 6 To 13
    If Cells(i, 13) <> "" Then
    m = Application.match(Cells(5, 13), Columns(1), 0)
    j = Application.match(Cells(i, 12), Rows(1), 0)
    Cells(m, j).Value = Cells(i, 13).Value
    Cells(m, 2).Value = Cells(4, 13).Value
    k = Application.match(Cells(i, 12), Worksheets("sheet2").Rows(1), 0)
    n = Worksheets("sheet2").Range("A" & Rows.Count).End(xlUp).Row
    Worksheets("sheet2").Cells(n + 1, 1).Value = Cells(5, 13).Value
    Worksheets("sheet2").Cells(n + 1, k).Value = Cells(i, 13).Value
    Worksheets("sheet2").Cells(n + 1, 2).Value = Cells(4, 13).Value
    Else
    End If
    
    Next i
    
    End Sub

    In the attached file you can click the button in cell L2 to run the macro. The history of all prices is in sheet2. The summary table is in sheet1 and the input range is M4:M13 in sheet1. The number of types and apple orchards can be adapted as required.

Resources