abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,489
- Office Version
- 2019
- 2010
- Platform
- Windows
Hi guys
I search to implement this code for multiple sheets and show result for multiple sheets
this code will search data for INVOICE sheet and combine data based on column D and summing values in columns H,J and column I=column J/ column H and the result will be in sales sheet, but I want implementing code for multiple sheet and show result for multiple sheets ( should merge for each sheet individual )
so the code should search for sheets(sales,purchase,report) and the result should show in sheets(OUTCOM,RESULT,MAIN)
if anybody interest and doesn't understand code I will post data .
thanks
I search to implement this code for multiple sheets and show result for multiple sheets
this code will search data for INVOICE sheet and combine data based on column D and summing values in columns H,J and column I=column J/ column H and the result will be in sales sheet, but I want implementing code for multiple sheet and show result for multiple sheets ( should merge for each sheet individual )
so the code should search for sheets(sales,purchase,report) and the result should show in sheets(OUTCOM,RESULT,MAIN)
if anybody interest and doesn't understand code I will post data .
VBA Code:
Sub test1()
Dim ws, a, i As Long, w, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
Set ws = Sheets("invoice")
If ws.Name <> "sales" Then
a = ws.Cells(1).CurrentRegion.Value
For i = 2 To UBound(a, 1)
If a(i, 4) <> "" Then
If Not dic.exists(a(i, 4)) Then
ReDim w(1 To 10)
w(4) = a(i, 4): w(5) = a(i, 5): w(6) = a(i, 6): w(7) = a(i, 7)
Else
w = dic(a(i, 4))
End If
w(8) = w(8) + a(i, 8): w(10) = w(10) + a(i, 10): w(9) = w(10) / w(8)
dic(a(i, 4)) = w
End If
Next
End If
With Sheets("sales").Cells(1).CurrentRegion
.Offset(1).ClearContents
If dic.Count Then
With .Rows(2).Resize(dic.Count)
.Value = Application.Index(dic.Items, 0, 0)
.Columns("h:j").NumberFormat = "#,##0.00"
.Columns(3) = Evaluate("row(1:" & .Rows.Count & ")")
End With
End If
End With
End Sub