how implement this code for each sheet separately instead of repeating

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,430
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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,215,700
Messages
6,126,283
Members
449,308
Latest member
VerifiedBleachersAttendee

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