extract data from the lastrow contains specific word based on date today

abdo meghari

Well-known Member
Joined
Aug 3, 2021
Messages
651
Office Version
  1. 2019
Hello
I want to extract data for specific information with the formatting as in original sheets as I did it in REPORT sheet
I want to extract for the DATE and INV.NO,TOTAL from each row contains SUM word based on date today .
so in REPORT sheet should create sheet name in above as I did it and make separated range for each sheet and sum the whole amounts for TOTAL column .

SS.xlsm
ABCDEFGHI
1ITEMDATEINV.NOBRANDTYPEORIGINQTY PRICETOTAL
212023/06/10BSJ_23444BS 215/60R16ER30JAP4.00430.001,720.00
3SUM2023/06/10BSJ_234441,720.00
412023/06/10BSJ_23445GO 1200R20AZ0026CHI2.00955.001,910.00
5SUM2023/06/10BSJ_234451,910.00
612023/09/15BSJ_23446GO 1200R20AZ0026CHI2.00950.001,900.00
722023/09/15BSJ_23446GO 1200R21AZ0027CHI3.001,000.003,000.00
8SUM2023/09/15BSJ_234464,900.00
912023/09/15BSJ_23447BS 1200R20G580JAP1.002,000.002,000.00
1022023/09/15BSJ_23447BS 1200R20G580THI1.002,000.002,000.00
1132023/09/15BSJ_23447BS 1200R20R187THI1.002,000.002,000.00
12SUM2023/09/15BSJ_234476,000.00
SR




SS.xlsm
ABCDEFGHI
1ITEMDATEINV.NOBRANDTYPEORIGINQTY PRICETOTAL
212023/06/15BSTR_23448BS 750R16R230JAP4.00500.002,000.00
322023/06/15BSTR_23448BS 700R16R230JAP2.00400.00800.00
4SUM2023/06/15BSTR_234482,800.00
512023/09/15BSTR_23449GO 1200R20AZ0026CHI1.00920.00920.00
622023/09/15BSTR_23449GO 1200R20AZ0083CHI2.001,000.002,000.00
7SUM2023/09/15BSTR_234492,920.00
812023/09/15BSTR_23450BS 1200R20G580JAP1.001,800.001,800.00
922023/09/15BSTR_23450BS 1200R20G580THI1.001,800.001,800.00
1032023/09/15BSTR_23450BS 1200R20R187THI1.001,800.001,800.00
11SUM2023/09/15BSTR_234505,400.00
SVR





result should be

المصنف2.xlsm
ABCD
1SR
2ITEMDATEINV.NOTOTAL
312023/09/15BSJ_234464,900.00
422023/09/15BSJ_234476,000.00
5SUM10,900.00
6
7
8SVR
9ITEMDATEINV.NOTOTAL
1012023/09/15BSTR_234492,920.00
1122023/09/15BSTR_234505,400.00
12SUM8,320.00
REPORT
Cell Formulas
RangeFormula
D5,D12D5=SUM(D3:D4)



notice : my real data could be 6000 rows for each sheet and every time I will add and change data in others sheets then should delete data in REPORT sheet before brings data when every time run the macro .
thanks
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try this
VBA Code:
Sub Report()
  Dim sh1 As Worksheet
  Dim sh As Variant, arrsh As Variant, a() As Variant
  Dim i, s1&, s2&, k&, n&, lr&
  Dim nTotal As Double
  Dim f As Range
  Dim cell As String, wcolor As Variant, wcolor2 As Variant
    
  Set sh1 = Sheets("SR")
  wcolor = sh1.Range("A1").Interior.Color
  wcolor2 = sh1.Range("A:A").Find("SUM", , xlValues, xlWhole).Interior.Color
  
  For Each sh In Array("SR", "SVR")
    s1 = s1 + WorksheetFunction.CountIfs(Sheets(sh).Range("A:A"), "SUM", Sheets(sh).Range("B:B"), Date)
  Next
  ReDim c(1 To s1 + 8, 1 To 4)
  k = 1
  
  For Each sh In Array("SR", "SVR")
    c(k, 2) = sh
    c(k + 1, 1) = "ITEM"
    c(k + 1, 2) = "DATE"
    c(k + 1, 3) = "INV.NO"
    c(k + 1, 4) = "TOTAL"
    k = k + 2
    n = 1
    nTotal = 0
    Erase a
    a = Sheets(sh).Range("A2", Sheets(sh).Range("I" & Rows.Count).End(3)).Value
  
    For i = 1 To UBound(a, 1)
      If a(i, 1) = "SUM" And a(i, 2) = Date Then
        c(k, 1) = n
        c(k, 2) = a(i, 2)
        c(k, 3) = a(i, 3)
        c(k, 4) = a(i, 9)
        nTotal = nTotal + a(i, 9)
        n = n + 1
        k = k + 1
      End If
    Next
    c(k, 1) = "SUM"
    c(k, 4) = nTotal
    k = k + 3
  Next
  
  With Sheets("REPORT")
    .Cells.Clear
    .Range("A1").Resize(UBound(c, 1), UBound(c, 2)).Value = c
    
    
    '******************** FORMAT CELLS ***************************
    .Columns("A:D").HorizontalAlignment = xlCenter
    .Columns("B:B").NumberFormat = "yyyy/mm/dd"
    .Columns("D:D").NumberFormat = "#,##0.00"
    .Range("A:D").Font.Name = "Times"
    .Range("A:D").Font.Size = 14
    .Columns("A:E").EntireColumn.AutoFit
    Set f = .Range("A:A").Find("ITEM", , xlValues, xlWhole)
    If Not f Is Nothing Then
      cell = f.Address
      Do
        f.Resize(1, 4).Font.Color = vbWhite
        f.Resize(1, 4).Interior.Color = wcolor
        lr = f.Cells(f.Rows.Count, 1).End(xlDown).Row - f.Row + 1
        With f.Resize(lr, 4).Borders
          .LineStyle = xlContinuous
          .Color = vbBlack
          .Weight = xlThin
        End With
        
        f.Offset(-1, 1).Font.Color = vbWhite
        f.Offset(-1, 1).Interior.Color = wcolor
        With f.Offset(-1, 1).Borders
          .LineStyle = xlContinuous
          .Color = vbBlack
          .Weight = xlThin
        End With
  
        Set f = .Range("A:A").FindNext(f)
      Loop While f.Address <> cell
    End If
    
    Set f = .Range("A:A").Find("SUM", , xlValues, xlWhole)
    If Not f Is Nothing Then
      cell = f.Address
      Do
        f.Interior.Color = wcolor2
        Set f = .Range("A:A").FindNext(f)
      Loop While f.Address <> cell
    End If
    '******************** END FORMAT CELLS ************************
  End With
End Sub



Regards
Dante Amor
 
Upvote 1
Solution
Hi Dante , I hope you're fine .
first I'm really sorry to delaying 🙏🙏
second the code works perfectly as I did it .👍
finally thank you so much . :)
 
Upvote 0
Hello Abdo, I'm fine, thanks for asking. I hope you are also well..

As always, happy to help you. It's always nice to help when you make the effort to explain in detail what you need.

Regards
Dante Amor
😇
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,105
Members
453,021
Latest member
Justyna P

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