Greetings friends of MREXCEL, good evening.
The file is used to calculate costs of products, and the macros automate the process of calculations and procedures, however, has a detail.
I explain the operation:
SHEET NATIONAL PRODUCTS COSTS:
In it the information of national products is registered, in it is placed:
A= Product
B= NATIONAL
C= Unit of Measurement
D= Product Quantity
E= Total Purchase Amount
F and G= (formula) Unit Cost per Unit of Measurement
The Macro sends the product information (columns A and B) to the PRODUCTS AND SERVICES PRICES sheet when entering the Total Purchase Amount (E).
PRODUCTS AND SERVICES PRICE SHEET:
Here you record the product information to calculate the price.
The information of the products comes from the sheet NATIONAL PRODUCTS COSTS and they are:
A = Name of the Product
B= NATIONAL.
The rest of the sheet is handled by filling in information in some columns and the rest is formula.
There are 1 drawback with the macro of NATIONAL PRODUCTS COSTS and that is what I want to solve:
In the sheet NATIONAL PRODUCT COSTS, if I update the cost (COLUMN E) of some product already registered previously, it runs the macro again, sending the last registered product to PRODUCTS AND SERVICES PRICES. You should simply update it and it should also be updated in PRODUCTS AND SERVICES PRICES.
Translated with DeepL.com (free version)
MACRO IN NATIONAL PRODUCTS COSTS
The file is used to calculate costs of products, and the macros automate the process of calculations and procedures, however, has a detail.
I explain the operation:
SHEET NATIONAL PRODUCTS COSTS:
In it the information of national products is registered, in it is placed:
A= Product
B= NATIONAL
C= Unit of Measurement
D= Product Quantity
E= Total Purchase Amount
F and G= (formula) Unit Cost per Unit of Measurement
The Macro sends the product information (columns A and B) to the PRODUCTS AND SERVICES PRICES sheet when entering the Total Purchase Amount (E).
PRODUCTS AND SERVICES PRICE SHEET:
Here you record the product information to calculate the price.
The information of the products comes from the sheet NATIONAL PRODUCTS COSTS and they are:
A = Name of the Product
B= NATIONAL.
The rest of the sheet is handled by filling in information in some columns and the rest is formula.
There are 1 drawback with the macro of NATIONAL PRODUCTS COSTS and that is what I want to solve:
In the sheet NATIONAL PRODUCT COSTS, if I update the cost (COLUMN E) of some product already registered previously, it runs the macro again, sending the last registered product to PRODUCTS AND SERVICES PRICES. You should simply update it and it should also be updated in PRODUCTS AND SERVICES PRICES.
Translated with DeepL.com (free version)
CALCULADORA DE PRECIOS Y COSTOS DATCHEL PLUS1.xlsm | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | ABC Ltda | ||||||||
2 | PRODUCT COST | ||||||||
3 | PRODUCT | NACIONAL | MEASURE UNIT | QUANTITY | PURCHASE AMOUNT | UNIT PRODUCT COST | |||
4 | $ | $ | |||||||
5 | A | NACIONAL | Kilo | 410,00 | 125.000,00 | 304,88 | por Kilo | ||
6 | B | NACIONAL | Kilo | 120,00 | 250.000,00 | 2.083,33 | por Kilo | ||
7 | C | NACIONAL | Kilo | 65,00 | 320.000,00 | 4.923,08 | por Kilo | ||
8 | D | NACIONAL | Kilo | 110,00 | 135.000,00 | 1.227,27 | por Kilo | ||
9 | E | NACIONAL | Kilo | 80,00 | 85.000,00 | 1.062,50 | por Kilo | ||
10 | F | NACIONAL | Kilo | 40,00 | 41.000,00 | 1.025,00 | por Kilo | ||
11 | G | NACIONAL | Kilo | 75,00 | 54.000,00 | 720,00 | por Kilo | ||
12 | H | NACIONAL | Kilo | 120,00 | 654.000,00 | 5.450,00 | por Kilo | ||
13 | I | NACIONAL | Kilo | 60,00 | 126.000,00 | 2.100,00 | por Kilo | ||
14 | J | NACIONAL | Kilo | 30,00 | 40.000,00 | 1.333,33 | por Kilo | ||
15 | K | NACIONAL | Kilo | 85,00 | 65.000,00 | 764,71 | por Kilo | ||
16 | L | NACIONAL | Kilo | 54,00 | 120.000,00 | 2.222,22 | por Kilo | ||
17 | M | NACIONAL | Kilo | 14,00 | 15.000,00 | 1.071,43 | por Kilo | ||
18 | NACIONAL | 0,00 | 0 | ||||||
19 | NACIONAL | 0,00 | 0 | ||||||
20 | NACIONAL | 0,00 | 0 | ||||||
COSTOS PRODUCTOS NACIONALES |
Cell Formulas | ||
---|---|---|
Range | Formula | |
A1 | A1 | ='INFORMACION GENERAL'!D5 |
F5:F20 | F5 | =IFERROR(E5/D5,0) |
G5:G20 | G5 | =C5 |
B5:B20 | B5 | =$B$3 |
Cells with Conditional Formatting | ||||
---|---|---|---|---|
Cell | Condition | Cell Format | Stop If True | |
G5:G10000 | Cell Value | =0 | text | NO |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
E5:E20 | Any value | |
A5:B10000 | Custom | =CONTAR.SI($A$5:$A$10000;A5)<=1 |
C5:C10000 | List | =UNIDADES |
CALCULADORA DE PRECIOS Y COSTOS DATCHEL PLUS1.xlsm | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
1 | ABC Ltda | ||||||
2 | PRICES PRODUCTS | ||||||
3 | PRODUCT | PRODUCT NATIONAL | MEASURE UNIT | UNIT PRODUCT COST | SALES | ||
4 | OR | ||||||
5 | IMPORTED | $ | 0 | ||||
6 | A | NACIONAL | Kilo | 304,88 | |||
7 | B | NACIONAL | Kilo | 2.083,33 | |||
8 | C | NACIONAL | Kilo | 4.923,08 | |||
9 | D | NACIONAL | Kilo | 1.227,27 | |||
10 | E | NACIONAL | Kilo | 1.062,50 | |||
11 | F | NACIONAL | Kilo | 1.025,00 | |||
12 | F | NACIONAL | Kilo | 1.025,00 | |||
13 | G | NACIONAL | Kilo | 720,00 | |||
14 | H | NACIONAL | Kilo | 5.450,00 | |||
15 | I | NACIONAL | Kilo | 2.100,00 | |||
16 | J | NACIONAL | Kilo | 1.333,33 | |||
17 | K | NACIONAL | Kilo | 764,71 | |||
18 | L | NACIONAL | Kilo | 2.222,22 | |||
19 | M | NACIONAL | Kilo | 1.071,43 | |||
20 | |||||||
21 | |||||||
PRECIOS PRODUCTOS Y SERVICIOS |
Cell Formulas | ||
---|---|---|
Range | Formula | |
A1 | A1 | ='INFORMACION GENERAL'!D5 |
E5 | E5 | =SUM(E6:E9998) |
C6:C21 | C6 | =IFERROR(IF(B6="NACIONAL",VLOOKUP(A6,'COSTOS PRODUCTOS NACIONALES'!$A$5:$G$10000,3,0),VLOOKUP(A6,#REF!,3,0))," ") |
D6:D21 | D6 | =IFERROR(IF(B6="NACIONAL",VLOOKUP(A6,'COSTOS PRODUCTOS NACIONALES'!$A$5:$G$10000,6,0),VLOOKUP(A6,#REF!,23,0))," ") |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
A6:A18 | Custom | =CONTAR.SI($A$5:$A$9998;A6)<=1 |
MACRO IN NATIONAL PRODUCTS COSTS
VBA Code:
Sub EnviarDatosCostosProductosNacionalesAPreciosProductosYServiciosA()
Application.ScreenUpdating = False
Dim ult, ult1 As Long
Dim rng As Range
ult2 = Sheets("COSTOS PRODUCTOS NACIONALES").Range("A" & Rows.Count).End(xlUp).Row
ult3 = Sheets("COSTOS PRODUCTOS NACIONALES").Range("B" & Rows.Count).End(xlUp).Row
ult = Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Range("A" & Rows.Count).End(xlUp).Row + 1
ult1 = Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Range("B" & Rows.Count).End(xlUp).Row + 1
Application.ScreenUpdating = False
Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Range("B" & ult1) = Sheets("COSTOS PRODUCTOS NACIONALES").Range("B" & ult3).Value
Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Range("A" & ult1) = Sheets("COSTOS PRODUCTOS NACIONALES").Range("A" & ult2).Value
Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Select
MsgBox ("SE HA ENVIADO AL MODULO PRECIOS PRODUCTOS Y SERVICIOS, LA INFORMACIÓN DE ESTE PRODUCTO O SERVICIO." & vbCr & Chr(13) & _
"POR FAVOR COMPLETE LA INFORMACIÓN SOLICITADA" & Chr(13) & _
"!OPERACIÓN REALIZADA SATISFACTORIAMENTE¡"), vbInformation, "CALCULADORA DE PRECIOS Y COSTOS DATCHEL PLUS"
Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Range("E" & ult1).Select
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row > 4 Then
If Target.Address Like "$E$*" Then
If Range("E" & Target.Row) > 0 Then
Application.ScreenUpdating = False
Call EnviarDatosCostosProductosNacionalesAPreciosProductosYServiciosA
End If
End If
End If
Dim prod$, ufo&, ufd&
Dim pro_d As Range
Dim rDependents As Range
uf = Range("C" & Rows.Count).End(xlUp).Row
'prod = TempCombo
prod = Range("A" & Target.Row).Value
If Application.Intersect(Target, Range("C6:C" & uf)) Is Nothing And _
Application.Intersect(Target, Range("D6:D" & uf)) Is Nothing And _
Application.Intersect(Target, Range("E6:E" & uf)) Is Nothing Then
Exit Sub
End If
If Worksheets("COSTOS PRODUCTOS NACIONALES").Range("F" & Target.Row).Value > 0 Then
With Sheets("PRECIOS PRODUCTOS Y SERVICIOS")
ufd = .Range("A" & Rows.Count).End(xlUp).Row
Set pro_d = .Range("A6:A" & ufd).Find(prod)
pro_d.Offset(, 1) = Worksheets("COSTOS PRODUCTOS NACIONALES").Range("B" & Target.Row).Value
End With
End If
End Sub
Last edited by a moderator: