Last row insert formulas

swingline

New Member
Joined
Oct 29, 2019
Messages
15
I need some help. I get a few reports like this on a weekly basis the largest one only containing about 150 rows and 26 columns. What I would like to do is use a macro to add a few things to the bottom of each sheet. Each sheet is dynamic in its number of rows and columns.

12346530-Nov-20197-Jul-21193-Feb-202020-Jan-202030-Jun-202130-Jun-20207-Jul-21194-Oct-202027-Jun-202027-Dec-2019
12346528-Dec-20197-Jul-211916-Jan-20206-Dec-2019N/A31-Jan-20207-Jul-211920-Mar-202027-Jun-202027-Dec-2019
1234653-Jan-20207-Jul-211910-Jan-201926-Apr-202013-Dec-202030-Sep-20207-Jul-21198-Jan-2020N/AN/A
12346531-Dec-20197-Jul-211917-Jun-202023-Dec-2019N/A30-Jun-20207-Jul-211926-Jul-2018N/AN/A
12346529-Dec-20197-Jul-211917-Jun-202011-Apr-20207-Sep-202031-Dec-20197-Jul-211923-Oct-2020N/AN/A
12346513-Dec-20197-Jul-211917-Jun-20203-Jan-2020N/A29-Feb-2020N/A26-Dec-2019N/AN/A
12346518-Oct-20197-Jul-211923-Jan-2020N/A7-Sep-202029-Feb-20207-Jul-211928-Feb-201917-Oct-201817-Apr-2018
1234652-Nov-20197-Jul-211923-Jan-202021-Mar-202020-Feb-202231-Jul-20207-Jul-211916-Jul-2021N/AN/A
1234655-Jan-20207-Jul-21196-Feb-20209-Mar-20207-Sep-202030-Sep-20207-Jul-211924-Aug-201825-Jun-201925-Dec-2018
12346526-Dec-20197-Jul-211919-Jun-202027-Mar-20206-Apr-202031-May-20207-Jul-211918-Oct-20188-Feb-2019N/A
1234652-Jan-20207-Jul-211927-May-20193-Apr-20205-Mar-202130-Sep-20207-Jul-21198-May-2020N/AN/A
M1234654-Jan-20207-Jul-211910-Jan-201922-Mar-202027-Sep-202130-Sep-20207-Jul-211929-Dec-2017N/AN/A
M1234652-Jan-20207-Jul-211919-Jun-20201-Mar-2020N/A31-Jul-20207-Jul-211918-Sep-202023-Oct-201823-Apr-2018
M12346531-Dec-20197-Jul-211916-Jan-20205-May-20204-Apr-202131-Dec-20197-Jul-211926-Jul-2018N/AN/A
M12346520-Dec-20197-Jul-211916-Jan-202024-Jan-202030-Mar-202031-Oct-202018-Jul-211920-Dec-202026-Jan-201826-Jul-2017
M12346522-Dec-20197-Jul-211910-Jan-201917-Feb-20201-Apr-202131-Aug-20207-Jul-211922-Jun-201823-Oct-201923-Feb-2019
M12346529-Dec-20197-Jul-211923-Jan-202025-Apr-20205-Mar-202130-Jun-20207-Jul-21198-May-2020N/AN/A
M12346526-Dec-20197-Jul-211910-Jan-20192-Feb-202013-Dec-202031-Mar-20207-Jul-21198-Jan-2020N/AN/A

<tbody>
</tbody>



These are the rows that I would like to add to the bottom of the sheet. The first two rows should repeat the same across to the last column below each date column. The date data always starts at row 13 but last row and column change week to week.

Out of date=COUNTIFS(B13:B18,"<="&TODAY(),A13:A18,"<>M*")+COUNTIFS(B13:B18,"N/A",A13:A18,"<>GAL*")
Out of Date + M=COUNTIFS(B13:B18,"<="&TODAY())+COUNTIFS(B13:B18,"N/A")
total =COUNTIFS(A13:A18,"*",A13:A18,"<>M*")
total +M=COUNTIFS(A13:A18,"*"

<tbody>
</tbody>












Any help would be greatly appreciated.
 
Last edited by a moderator:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
My OP has an Error this should be changed

Out of date=COUNTIFS(B13:B18,"<="&TODAY(),A13:A18,"<>M*")+COUNTIFS(B13:B18,"N/A",A13:A18,"<>GAL*")

<tbody>
</tbody>




to
Out of date=COUNTIFS(B13:B18,"<="&TODAY(),A13:A18,"<>M*")+COUNTIFS(B13:B18,"N/A",A13:A18,"<>M*")

<tbody>
</tbody>
 
Upvote 0
For the first two, how about
Code:
Sub swingline()
    Dim UsdCols As Long
    UsdCols = Cells.Find("*", , xlValues, , xlByColumns, xlPrevious, , , False).Column
    With Range("A" & Rows.Count).End(xlUp)
        .Offset(1, 1).Resize(, UsdCols - 1).FormulaR1C1 = "=COUNTIFS(R13C:R[-1]C,""<=""&TODAY(),R13C1:R[-1]C1,""<>M*"")+COUNTIFS(R13C:R[-1]C,""N/A"",R13C1:R[-1]C1,""<>M*"")"
        .Offset(2, 1).Resize(, UsdCols - 1).FormulaR1C1 = "=COUNTIFS(R13C:R[-2]C,""<=""&TODAY())+COUNTIFS(R13C:R[-2]C,""N/A"")"
    End With
End Sub
 
Upvote 0
Can you manage the other two formulae, or do you need help with them?
 
Upvote 0
Glad to hear that & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,930
Members
449,094
Latest member
teemeren

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