copy lastrow for each name in range from sheet to another

Abdo

Board Regular
Joined
May 16, 2022
Messages
183
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hi
I want showing the lastrow for each name from sheet to another based on column C in sheet filter with ignore columns A,B,D
sheet filter
f .xlsm
ABCDEFG
1DATEINVOICE NOCLIENT NODESCRIBEDEBITCREDITBALANCE
21/1/2022-ABDEND1OPENNING20,000.00-20,000.00
31/4/2022PA-B3ABDEND1PA20,000.00-40,000.00
41/5/2022SA-B35ABDEND1SA-1,000.0039,000.00
51/2/2022PA-B36ABDEND2PA1,000.00-1,000.00
61/7/2022PA-B37ABDEND2PA1,000.00-2,000.00
71/13/2022PA-B45ABDEND2PA1,000.00100.002,900.00
81/3/2022PA-B38ABDEND3openning-200.00-200.00
91/6/2022PA-B39ABDEND3PA5,000.00-4,800.00
101/8/2022PA-B40ABDEND3PA5,000.00-9,800.00
111/9/2022PA-B41ABDEND3PA5,000.00-14,800.00
121/10/2022PA-B42ABDEND3PA2,000.00-16,800.00
131/11/2022PA-B43ABDEND3PA1,000.00100.0017,700.00
141/12/2022PA-B44ABDEND4PA1,000.00100.00900.00
filter

the result in sheet OUTPUT from row2 with the same borders & formatting . with considering any changing or adding new data in sheet filter should update in sheet output .
f.xlsm
ABCDE
1ITEMCLIENT NODEBITCREDITBALANCE
21ABDEND1-1,000.0039,000.00
32ABDEND21,000.00100.002,900.00
43ABDEND31,000.00100.0017,700.00
54ABDEND41,000.00100.00900.00
output


thanks
 
I hope this will run according to your expectation and that you will be able to set final format as you need.
VBA Code:
Sub CreateReportUniqueLastRow()

   Dim vWS1 As Worksheet, vWS2 As Worksheet
   Dim vLastRow As String
   Dim vRng As Range, vRng1 As Range, _
            vRng2 As Range, vRng3 As Range, vR As Range
   Dim vN As Long
   Dim vAUnique As Variant, vA As Variant, vFind

   Application.ScreenUpdating = False
   Set vWS1 = Sheets("filter")
   Set vWS2 = Sheets("output")
   vLastRow = vWS1.Cells(Rows.Count, "C").End(xlUp).Address
   Set vRng = vWS1.Range("A2", vWS1.Range(vLastRow).Offset(, 4))
   Set vRng2 = vRng.Columns(3)
   With CreateObject("Scripting.Dictionary")
        For Each vR In vWS1.Range(vRng2.Address)
            If Not .exists(vR.Value) And Not vR.Value = "" Then _
               .Add vR.Value, ""
        Next vR
        vAUnique = Application.Transpose(.keys)
   End With
   Set vRng1 = Union(vWS1.Cells(1, 1), vWS1.Cells(1, 3), _
    vWS1.Cells(1, 5).Resize(, 3))
   vRng1.Copy vWS2.Cells(1, 1).Resize(, 5)
   ReDim vA(1 To UBound(vAUnique), 1 To 5)
   For vN = 1 To UBound(vAUnique)
      vFind = vRng.Columns(3).Find( _
         vAUnique(vN, 1), , , xlWhole, , xlPrevious, True).Row - 1
      vA(vN, 1) = vN
      vA(vN, 2) = vRng(vFind, 3)
      vA(vN, 3) = vRng(vFind, 5)
      vA(vN, 4) = vRng(vFind, 6)
      vA(vN, 5) = vRng(vFind, 7)
   Next vN
   vWS2.Range("A2").Resize(UBound(vAUnique), 5) = vA
   Set vRng3 = vWS2.Range("A2").Resize(UBound(vAUnique), 5)
'setting final format
   vRng3.Borders.LineStyle = vWS1.[A2].Borders.LineStyle
   vRng3.Interior.Color = vWS1.[A2].Interior.Color
   vRng3.VerticalAlignment = vWS1.[A2].VerticalAlignment
   vRng3.Font.Bold = vWS1.[A2].Font.Bold
   vRng3.Font.Size = vWS1.[A2].Font.Size
   vRng3.Font.Italic = vWS1.[A2].Font.Italic
   vRng3.Columns("C:E").NumberFormat = "0.00"
   vWS2.Columns("A:E").AutoFit
   vWS2.Columns("B").ColumnWidth = vWS1.Columns("C").ColumnWidth
   Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
this is better gives 0.07 sec
thanks gain:)
 
Upvote 0
When you open workbook first time and goes to speed test,
code runs slowly, but second time it will runs faster.
Try to initiate code on "Workbook Open" event before test.
VBA Code:
Private Sub Workbook_Open()
   CreateReportUniqueLastRow
   Sheets("output").Columns("A:E").Delete
End Sub
 
Upvote 0
I put it and save & close the file and when open the file gives compile error variable not defined for this word vFind in this line
VBA Code:
 vFind = vRng.Columns(3).Find( _
 
Upvote 0

Forum statistics

Threads
1,215,275
Messages
6,124,002
Members
449,137
Latest member
abdahsankhan

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