VBA to put counta subtotal at end of column

nirvehex

Well-known Member
Joined
Jul 27, 2011
Messages
505
Office Version
  1. 365
Platform
  1. Windows
Hi,

How would I put this function into a VBA code that looks at column A and puts this function in the cell after the very last cell with any data in it. Assume there are no blanks within the data in column A.

So I want to find the last row of data in column A and run this formula in the next row down. Furthermore how do I make the ending cell (a14) so it automatically runs the formula to the last cell with data in it.

Code:
=SUBTOTAL(103,'1 yr of PO''s'!$A$2:$A$14)

Thanks.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try this UNTESTED code:

Code:
Sub SubTtl()

    Dim x As Long
    
    x = Range("A" & Range("A" & Rows.Count).End(xlUp).Row)
    Range("A" & x).Offset(2, 0).Formula = _
        "=SUBTOTAL(103,'1 yr of PO''s'!$A$2:$A$" & x & ")"
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,650
Messages
6,126,019
Members
449,280
Latest member
Miahr

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