Link to home
Start Free TrialLog in
Avatar of Andreas Hermle
Andreas HermleFlag for Germany

asked on

Enter Formula into cell below filtered list using VBA

Dear Experts:

I would like to enter the formula in line 7 in another way, i.e. no hardcoding of the range.

The Formula is to be entered into Column A, two cells below the last filled cell of the filtered list no matter how many rows there are.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas


Sub Enter_SubTotal_End_of_Filtered_List()


    ThisWorkbook.Worksheets("3_Gesamtliste").Range("A1:M" & Range("A" & Rows.Count).End(xlUp).Row).AutoFilter Field:=4, Criteria1:="="
    
    
        Range("A13980").Formula = Application.WorksheetFunction.Subtotal(9, Range("A1:A" & Range("B" & Rows.Count).End(xlUp).Row))
      
  
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you format the data as a Table then you don't need VBA to add a formula. You can have a total row which can automatically a a sum of total, or count, etc,which works as SubTotal
Avatar of Andreas Hermle

ASKER

Hi Roy, I am ware of this fact and I normally always use tables, but in this special case I regrettably cannot use a table.

Thank you, Roy, anyway.
Great Rgonzo, works as desired. Thank you very much for it.

Regards, Andreas