insert total row with advanced filter based on two date and name's client

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hi
i have this code it brings data from sheet1 to sheet 2 based on two date and name's client as in sheet2 but i would add line code insert row total under the filling lastrow sum the values
VBA Code:
Sub Test1()

        Dim CustID As String: cn = sheet2.[g3].Value
        Dim FromDt As Long: FromDt = sheet2.[C3].Value
        Dim ToDt As Long: ToDt = sheet2.[e3].Value

Application.ScreenUpdating = False
      
        sheet2.[A7].CurrentRegion.Offset(1).Clear
      
        With sheet1.[A3].CurrentRegion
                .AutoFilter 4, cn
                .AutoFilter 1, ">=" & FromDt, xlAnd, "<=" & ToDt
                .Offset(1).EntireRow.Copy sheet2.Range("A" & Rows.Count).End(3)(2)
                .AutoFilter
        End With
      
       ' sheet2.[C3:g3].Clear
      
Application.ScreenUpdating = True

End Sub


INPUT
فلترة بين تاريخين واسم عميل.xlsm
ABCDEFGHI
1statement of customer
2dateCUSTOMER NOINVOICE NOCUSTOMER NAMEBALANCE OF FIRST DURITIONCREDITDEBITBALANCEWAY OF PAID
301/01/2019isd123bsj1200ALI10250900640cash
401/02/2019isd124bsj1201OMAR20300800480cash
530/05/2019isd125bsj1202MOHAMMED305098723416782290661bank
615/06/2019isd126bsj1203MAHMOUD404326543546cash
716/06/2019isd127bsj1204AHMED80432156781277bank
817/06/2019isd128bsj1205SARAH20778564-234cash
918/06/2019isd129bsj1206NORIE1099321212cash
1001/02/2019isd123bsj1207ALI10250900640cash
11
12
13
sheet1
Cell Formulas
RangeFormula
H7:H10,H3:H5H3=G3-(E3+F3)






OUTPUT
فلترة بين تاريخين واسم عميل.xlsm
ABCDEFGHI
1
2
3from date01/01/2019to date01/02/2019CNALI
4
5
6
7dateCUSTOMER NOINVOICE NOCUSTOMER NAMEBALANCE OF FIRST DURITIONCREDITDEBITBALANCEWAY OF PAID
801/01/2019isd123bsj1200ALI10250900640cash
901/02/2019isd123bsj1207ALI10250900640cash
10TOTAL2050018001280
sheet2
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi abdelfattah, please try the below code

Sub Test1()

Dim CustID As String: cn = Sheet2.[g3].Value
Dim FromDt As Long: FromDt = Sheet2.[C3].Value
Dim ToDt As Long: ToDt = Sheet2.[e3].Value
Dim lRow As Long

Range("A8:I1000").Clear

Application.ScreenUpdating = False

Sheet2.[A7].CurrentRegion.Offset(1).Clear

With Sheet1.[A3].CurrentRegion
.AutoFilter 4, cn
.AutoFilter 1, ">=" & FromDt, xlAnd, "<=" & ToDt
.Offset(1).EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2)
.AutoFilter
End With

' sheet2.[C3:g3].Clear

lRow = Cells(Rows.Count, 1).End(xlUp).Row

Cells(lRow + 1, 1) = "Total"

For o = 5 To 8
Cells(lRow + 1, o) = Application.WorksheetFunction.Sum(Cells(lRow, o))
Next o


Application.ScreenUpdating = True

End Sub
 
Upvote 0
thanks but it should do that in sheet2 not sheet1 and it doesn't sum the values it copy the last value each column
it should sum the values
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

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