Hello vipvanilla,
The macro below has been added to the attached workbook. A button has been added to the "Addendum" worksheet. A new worksheet has also been added named "Tables". This holds the two tables that will be copied below the main table.
Here is the code for the macro "AddTables" in Module2.
Sub AddTables()
Dim Cnt As Long
Dim Data As Variant
Dim EndRow As Range
Dim EquipList As Range
Dim n As Long
Dim r As Long
Dim RowCnt As Long
Dim TableRow As Long
Dim TableWks As Worksheet
Dim Wks As Worksheet
Set Wks = Worksheets("Addendum")
Set TableWks = Worksheets("Tables")
' Entire table range.
Set EquipList = Wks.Range("A10").CurrentRegion
' Last row entry in the equipment list.
Set EndRow = EquipList.Cells(EquipList.Rows.Count, "B").End(xlUp)
' Check data has been entered.
If EndRow.Row < EquipList.Row Then Exit Sub
' Delete any previous Equipment Tables.
r = EquipList.Row + EquipList.Rows.Count - 1
n = Wks.Cells(Rows.Count, "A").End(xlUp).Row
If n > r Then
Wks.Range(Wks.Rows(r + 1), Wks.Rows(n)).Delete Shift:=xlUp
End If
' Prepare the Equipment Tables.
TableRow = 3
TableWks.Rows(3).EntireRow.ClearContents
TableWks.UsedRange.Offset(3, 0).ClearContents
RowCnt = EndRow.Row - EquipList.Row + 1
' Fill in the Equipment Tables.
For r = 2 To RowCnt
If EquipList.Cells(r, 2) <> "" Then
Data = EquipList.Range("A" & r, "C" & r).Value
ReDim Preserve Data(1 To 1, 1 To 4)
With TableWks
.Rows(TableRow).FillDown
Data(1, 4) = EquipList.Cells(r, 5).Value
.Range(.Cells(TableRow, "F"), .Cells(TableRow, "I")).Value = Data
Data(1, 4) = EquipList.Cells(r, 4).Value - Data(1, 4)
.Range(.Cells(TableRow, "A"), .Cells(TableRow, "D")).Value = Data
TableRow = TableRow + 1
End With
End If
Next r
' Add Equipment Remaining at Facility Table.
r = EquipList.Rows.Count + EquipList.Row + 2
TableWks.Range("A1").CurrentRegion.Copy Wks.Cells(r, "A")
' Add Equipment Returned to facility Table.
r = r + TableWks.Range("F1").CurrentRegion.Rows.Count + 2
TableWks.Range("F1").CurrentRegion.Copy Wks.Cells(r, "A")
End Sub
Bookmarks