I have attached an excel file that I downloaded from the sales branch website and its information is in sheet one, I want the clean information to be converted like sheet two. For each product and its branch code, the amount of sales and inventory should be entered in front of it so that I know which branch has the sales amount and the amount of inventory for the product and product code. Please provide solution and guide me.
Please guide step by step so that I can do. Thanks
With sheet1 is raw data, sheet2 is output
Because of there are arabic language (I am not sure what it is) those can not input within code edit window, I use cell AL1 to store it ("cod" in arabic in cell AM45? I am not sure, but try)
Just give it a shot.
Hit the "RUN" button to activate code.
PHP Code:
Option Explicit
Sub test()
Dim lr&, i&, j&, k&, tu&, t&, m&, rng
Dim arr(1 To 10000, 1 To 3), res(1 To 10000, 1 To 5), ary
ary = Array(33, 25, 20, 13)
With Sheets("sheet1")
lr = .Cells(Rows.Count, "AH").End(xlUp).Row
rng = .Range("B14:AM" & lr).Value
End With
For i = 1 To UBound(rng)
If rng(i, 38) = "cod" Or rng(i, 38) = Range("AL1").Value Then
k = k + 1: arr(k, 1) = i - 1: arr(k, 2) = rng(i, 34): arr(k, 3) = rng(i - 1, 34)
End If
Next
For i = 1 To k
If i < k Then tu = arr(i + 1, 1) - 1 Else tu = UBound(rng)
For j = 0 To UBound(ary)
For t = arr(i, 1) To tu
If rng(t, ary(j)) <> "" Then
m = m + 1: res(m, 1) = arr(i, 2): res(m, 2) = arr(i, 3)
res(m, 3) = rng(t, ary(j)): res(m, 4) = rng(t, ary(j) - 1): res(m, 5) = rng(t, ary(j) - 2)
End If
Next
Next
Next
Sheets("Sheet2").Activate
Range("A2:E10000").ClearContents
Range("A2").Resize(m, 5).Value = res
End Sub
Yes - but when you upload the original file in your file, the place osaleDocument_sply_prd_CostCenter_WithPrize (2).xlsxf sale and inventory will be changed, and the sales numbers of each region will be inserted instead of the inventory.
Bookmarks