how implement this code for each sheet separately instead of repeating

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,489
Office Version
  1. 2019
  2. 2010
Platform
  1. 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 .

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
thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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