HI all
the attached file
contains 2 tabs
1.R_Jetwash
2.R_Jetwash_table
1.R_Jetwash contains two areas where the user populates the data A to N and Q TO AB ( (please take into account that the number of rows can increase substantially)
A TO N are volumes(sales) and Q to AB are prices
what the macro has to do is to calculate the revenue (volume *price) in each site per month
For example Revenue in Jan 18 in site 32 =
4000 ( tab=R_Jetwash cell= c12)*0.83 ( tab=R_Jetwash cell= Q12) =332
2. R_Jetwash_table
this tab will show the result of each site in each month
(the macro below is very similar, the difference is that has a tab called volumes, that tab was another factor to multiply in the above calculation. that tab is no longer in use in the above example
perhaps you can use it as a reference. if it is confusing you please ignore it)
Sub MakeTable()
Dim vol As Variant
Dim con As Variant
Dim tbl As Variant
Dim i As Long
Dim j As Long
Dim iRow As Long
Dim dic As Object
With ThisWorkbook
With .Worksheets("VOLUMES")
vol = .Range("A2").Resize(.Cells(.Rows.Count, "A").End(xlUp).Row, 5)
End With
With .Worksheets("R_Jetwash")
con = .Range("A1").Resize(.Cells(.Rows.Count, "A").End(xlUp).Row, 28)
End With
End With
Set dic = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(vol)
dic(vol(i, 2) & "|" & vol(i, 4)) = vol(i, 5)
Next
ReDim tbl(1 To UBound(con) * 12, 1 To 4)
For i = 1 To UBound(con) - 1
For j = 3 To 14
iRow = (i - 1) * 12 + j - 2
tbl(iRow, 1) = con(i + 1, 1)
tbl(iRow, 2) = con(1, j)
tbl(iRow, 3) = con(i + 1, 2)
tbl(iRow, 4) = dic(con(i + 1, 1) & "|" & con(1, j)) * con(i + 1, j) * con(i + 1, j + 14)
Next
Next
Application.ScreenUpdating = False
With ThisWorkbook
With .Worksheets("R_Jetwash_table")
.Cells.Clear
.Range("A1:D1") = Array("Site", "Month", "Jetwash", "Amount")
.Range("A2").Resize(UBound(tbl, 1), UBound(tbl, 2)) = tbl
.Columns("B:B").NumberFormat = "mmm-yy"
.Columns("D:D").NumberFormat = "_-* #,##0_ -;-* #,##0_ -;_-* ""-""?_-;_-@_-"
.Columns("A:D").EntireColumn.AutoFit
End With
End With
End Sub
Bookmarks