Updating data in cell, run the macro again and it should not happen.

leobrice

New Member
Joined
Jun 14, 2024
Messages
32
Office Version
  1. 2013
Platform
  1. Windows
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)

CALCULADORA DE PRECIOS Y COSTOS DATCHEL PLUS1.xlsm
ABCDEFG
1ABC Ltda
2PRODUCT COST
3PRODUCTNACIONALMEASURE UNITQUANTITYPURCHASE AMOUNTUNIT PRODUCT COST
4$$
5ANACIONALKilo410,00125.000,00304,88por Kilo
6BNACIONALKilo120,00250.000,002.083,33por Kilo
7C NACIONALKilo65,00320.000,004.923,08por Kilo
8DNACIONALKilo110,00135.000,001.227,27por Kilo
9ENACIONALKilo80,0085.000,001.062,50por Kilo
10FNACIONALKilo40,0041.000,001.025,00por Kilo
11GNACIONALKilo75,0054.000,00720,00por Kilo
12HNACIONALKilo120,00654.000,005.450,00por Kilo
13INACIONALKilo60,00126.000,002.100,00por Kilo
14JNACIONALKilo30,0040.000,001.333,33por Kilo
15KNACIONALKilo85,0065.000,00764,71por Kilo
16LNACIONALKilo54,00120.000,002.222,22por Kilo
17MNACIONALKilo14,0015.000,001.071,43por Kilo
18NACIONAL0,000
19NACIONAL0,000
20NACIONAL0,000
COSTOS PRODUCTOS NACIONALES
Cell Formulas
RangeFormula
A1A1='INFORMACION GENERAL'!D5
F5:F20F5=IFERROR(E5/D5,0)
G5:G20G5=C5
B5:B20B5=$B$3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G5:G10000Cell Value=0textNO
Cells with Data Validation
CellAllowCriteria
E5:E20Any value
A5:B10000Custom=CONTAR.SI($A$5:$A$10000;A5)<=1
C5:C10000List=UNIDADES


CALCULADORA DE PRECIOS Y COSTOS DATCHEL PLUS1.xlsm
ABCDE
1ABC Ltda
2PRICES PRODUCTS
3PRODUCTPRODUCT NATIONALMEASURE UNITUNIT PRODUCT COSTSALES
4OR
5IMPORTED$0
6ANACIONALKilo304,88
7BNACIONALKilo2.083,33
8C NACIONALKilo4.923,08
9DNACIONALKilo1.227,27
10ENACIONALKilo1.062,50
11FNACIONALKilo1.025,00
12FNACIONALKilo1.025,00
13GNACIONALKilo720,00
14HNACIONALKilo5.450,00
15INACIONALKilo2.100,00
16JNACIONALKilo1.333,33
17KNACIONALKilo764,71
18LNACIONALKilo2.222,22
19MNACIONALKilo1.071,43
20
21
PRECIOS PRODUCTOS Y SERVICIOS
Cell Formulas
RangeFormula
A1A1='INFORMACION GENERAL'!D5
E5E5=SUM(E6:E9998)
C6:C21C6=IFERROR(IF(B6="NACIONAL",VLOOKUP(A6,'COSTOS PRODUCTOS NACIONALES'!$A$5:$G$10000,3,0),VLOOKUP(A6,#REF!,3,0))," ")
D6:D21D6=IFERROR(IF(B6="NACIONAL",VLOOKUP(A6,'COSTOS PRODUCTOS NACIONALES'!$A$5:$G$10000,6,0),VLOOKUP(A6,#REF!,23,0))," ")
Cells with Data Validation
CellAllowCriteria
A6:A18Custom=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:
CALCULADORA DE PRECIOS Y COSTOS DATCHEL PLUS1.xlsm
ABCDE
1Piscinas Aqualux S.A. DEFINITIVA
2PRECIO DE VENTA DE PRODUCTOS Y SERVICIOS
3PRODUCTO / SERVICIOPRODUCTO NACIONALUNIDAD DE MEDIDACOSTO UNITARIO PRODUCTOVENTAS ESTIMADAS MENSUALES UNIDADES
4O
5IMPORTADOU$10,125
6IMPORTADOIMPORTADO
7S1NACIONAL 1.00
8 52,000.00
9ANACIONALLitro1,875.00
10BNACIONALKilo11,555.56
11COSTOS DE SERVICIOSNACIONALServicio48,656.94124.00
12CNACIONALGalón10,000.0010,000.00
13D NACIONALLitro1,635.00
14
15
PRECIOS PRODUCTOS Y SERVICIOS
Cell Formulas
RangeFormula
A1A1='INFORMACION GENERAL'!D5
D5D5=MONEDAS!C2
E5E5=SUM(E6:E9998)
C14:C15,C6:C8C6=IFERROR(IF(B6="NACIONAL",VLOOKUP(A6,'COSTOS PRODUCTOS NACIONALES'!$A$5:$G$10000,3,0),VLOOKUP(A6,'COSTOS PRODUCTOS IMPORTADOS'!$A$5:$X$10000,3,0))," ")
Cells with Data Validation
CellAllowCriteria
A6:A15Custom=CONTAR.SI($A$5:$A$9998;A6)<=1



CALCULADORA DE PRECIOS Y COSTOS DATCHEL PLUS1.xlsm
ABCD
1Piscinas Aqualux S.A. DEFINITIVA
2PUNTO DE EQUILIBRIO GLOBAL MENSUAL
3INFORME MENSUALVENTAS MENSUALES ESTIMADAS Y/O REALESVENTA PROYECTADA MENSUALPRECIO DE VENTA
4MES: SEPTIEMBRE 2021UNIDADES UNIDADESU$
5PRODUCTOS Y SERVICIOS TOTALES →242417,848,209.76
6S1101017,699,115.04
7S214140.00
8IMPORTADOIMPORTADOIMPORTADO0.00
9
10AAA3,750.00
11BBB23,111.11
12COSTOS DE SERVICIOSCOSTOS DE SERVICIOSCOSTOS DE SERVICIOS98,682.35
13CCC20,281.25
14D D D 3,270.00
1500.00
1600.00
1700.00
1800.00
PUNTO DE EQUILIBRIO
Cell Formulas
RangeFormula
A1A1='INFORMACION GENERAL'!D5
A2A2=IF('COSTOS FIJOS'!A5="MENSUAL","PUNTO DE EQUILIBRIO GLOBAL MENSUAL","PUNTO DE EQUILIBRIO GLOBAL ANUAL")
A3A3=IF('COSTOS FIJOS'!A5="MENSUAL","INFORME MENSUAL","INFORME ANUAL")
C3C3=IF('COSTOS FIJOS'!A5="MENSUAL","VENTA PROYECTADA MENSUAL","VENTA PROYECTADA ANUAL")
D4D4=MONEDAS!C2
B5:D5B5=SUM(B6:B10000)
C10:C18,C6:C8C6=IF('COSTOS FIJOS'!$A$5="MENSUAL",B6,B6*12)
D10:D18,D6:D8D6=IFERROR(VLOOKUP(A6,'PRECIOS PRODUCTOS Y SERVICIOS'!$A$6:$W$10000,21,0),0)
Cells with Data Validation
CellAllowCriteria
A6:A18Custom=CONTAR.SI($A$5:$A$10000;A6)<=1


Remember that from COSTOS PRODUCTOS NACIONALES the product (column A) is sent to PRECIOS PRODUCTOS Y SERVICIOS and the PRECIOS PRODUCTOS Y SERVICIOS macro sends the product (column A) to PUNTO DE EQUILIBRIO (columna A) and that's it.

Now the macro PRECIOS PRODUCTOS Y SERVICIOS sends the product (column A) to PUNTO DE EQUILIBRIO to columns A and B.


MACRO IN PRECIOS PRODUCTOS Y SERVICIOS:

VBA Code:
Sub EnviarDatosPreciosProductosYServiciosAPuntoDeEquilibrio()

Dim ult As Long
Dim rng As Range
ult1 = Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Range("A" & Rows.Count).End(xlUp).Row

ult = Sheets("PUNTO DE EQUILIBRIO").Range("A" & Rows.Count).End(xlUp).Row + 1

Sheets("PUNTO DE EQUILIBRIO").Range("A" & ult) = Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Range("A" & ult1).Value

Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Select

'MsgBox (" SE HA ENVIADO AL MODULO COSTOS FIJOS LA INFORMACIÓN DE ESTE TRABAJADOR DE SUELDOS Y SALARIOS" & Chr(13) & _
"POR FAVOR COMPLETE LA INFORMACIÓN DE ESTE TRABAJADOR" & Chr(13) & _
"OPERACIÓN REALIZADA SATISFACTORIAMENTE"), vbInformation, "CALCULADORA DE RECETAS DATCHEL PRO"

'Sheets("PUNTO DE EQUILIBRIO").Range("D" & ult1).Select
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row > 5 Then
   If Target.Address Like "$A$*" Then
      If Range("A" & Target.Row) <> 0 Then
         Call EnviarDatosPreciosProductosYServiciosAPuntoDeEquilibrio
      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("B9:B" & uf)) Is Nothing And _
       Application.Intersect(Target, Range("C9:C" & uf)) Is Nothing And _
       Application.Intersect(Target, Range("D9:D" & uf)) Is Nothing And _
       Application.Intersect(Target, Range("E9:E" & uf)) Is Nothing And _
       Application.Intersect(Target, Range("F9:F" & uf)) Is Nothing And _
       Application.Intersect(Target, Range("G9:G" & uf)) Is Nothing And _
       Application.Intersect(Target, Range("H9:H" & uf)) Is Nothing Then
       Exit Sub
    End If
       
    If Worksheets("PRECIOS PRODUCTOS Y SERVICIOS").Range("A" & Target.Row).Value > 0 Then
        With Sheets("PUNTO DE EQUILIBRIO")
            ufd = .Range("A" & Rows.Count).End(xlUp).Row
            Set pro_d = .Range("A8:A" & ufd).Find(prod)
            pro_d.Offset(, 1) = Worksheets("PRECIOS PRODUCTOS Y SERVICIOS").Range("A" & Target.Row).Value
        End With
    End If
 
Last edited by a moderator:
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
The macro you posted is very confusing. Do you want the macro in PRECIOS PRODUCTOS Y SERVICIOS to work exactly the same way as the macro in COSTOS PRODUCTOS NACIONALES except that the product is copied to columns A and B of PUNTO DE EQUILIBRIO instead of just column A? Also, do you want to replace existing values in PUNTO DE EQUILIBRIO and place new values at the bottom of PUNTO DE EQUILIBRIO? Please clarify in detail.
 
Upvote 0
The macro you posted is very confusing. Do you want the macro in PRECIOS PRODUCTOS Y SERVICIOS to work exactly the same way as the macro in COSTOS PRODUCTOS NACIONALES except that the product is copied to columns A and B of PUNTO DE EQUILIBRIO instead of just column A? Also, do you want to replace existing values in PUNTO DE EQUILIBRIO and place new values at the bottom of PUNTO DE EQUILIBRIO? Please clarify in detail.
Hello mumps good morning!
I comment you:

To the PUNTO DE EQUILIBRIO sheet, only the product name of PRECIOS PRODUCTOS Y SERVICIOS (column A) must arrive, the information that goes in column B, is registered manually and the rest of the columns are formulas. In this case, it is not necessary to replace data.

Thanks mumps¡¡¡

Translated with DeepL.com (free version)
 
Upvote 0
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    If Intersect(Target, Range("A:A")) Is Nothing Or Target.Row < 6 Then Exit Sub
    If Range("A" & Target.Row) <> 0 Then
        With Sheets("PUNTO DE EQUILIBRIO")
            .Activate
            .Cells(.Rows.Count, "A").End(xlUp).Offset(1) = Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Cells(Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Rows.Count, "A").End(xlUp)
            .Cells(.Rows.Count, "A").End(xlUp).Offset(, 3).Select
        End With
        MsgBox (" SE HA ENVIADO AL MODULO COSTOS FIJOS LA INFORMACIÓN DE ESTE TRABAJADOR DE SUELDOS Y SALARIOS" & Chr(13) & _
        "POR FAVOR COMPLETE LA INFORMACIÓN DE ESTE TRABAJADOR" & Chr(13) & _
        "OPERACIÓN REALIZADA SATISFACTORIAMENTE"), vbInformation, "CALCULADORA DE RECETAS DATCHEL PRO"
    End If
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    If Intersect(Target, Range("A:A")) Is Nothing Or Target.Row < 6 Then Exit Sub
    If Range("A" & Target.Row) <> 0 Then
        With Sheets("PUNTO DE EQUILIBRIO")
            .Activate
            .Cells(.Rows.Count, "A").End(xlUp).Offset(1) = Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Cells(Sheets("PRECIOS PRODUCTOS Y SERVICIOS").Rows.Count, "A").End(xlUp)
            .Cells(.Rows.Count, "A").End(xlUp).Offset(, 3).Select
        End With
        MsgBox (" SE HA ENVIADO AL MODULO COSTOS FIJOS LA INFORMACIÓN DE ESTE TRABAJADOR DE SUELDOS Y SALARIOS" & Chr(13) & _
        "POR FAVOR COMPLETE LA INFORMACIÓN DE ESTE TRABAJADOR" & Chr(13) & _
        "OPERACIÓN REALIZADA SATISFACTORIAMENTE"), vbInformation, "CALCULADORA DE RECETAS DATCHEL PRO"
    End If
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
No, it does nothing mumps.
I started from COSTO DE PRODUCTOS NACIONALES adding a product, it sends it to PRECIOS PRODUCTOS Y SERVICIOS and the process stops there, it does not send the product to the column A of PUNTO DE EQUILIBRIO..
 
Upvote 0
Did you put the macro in the PUNTO worksheet code module?
 
Upvote 0
I’ll have another look at it tomorrow.
I wrote the product in column A of PUNTO DE EQUILIBRIO, and the next product was updated, but it should not work like that. Let me explain:

When I create a new product in COSTOS PRODUCTOS NACIONALES, from here it sends it to PRECIOS PRODUCTOS Y SERVICIOS and from here it then goes to PUNTO DE EQUILIBRIO.
I think the macro should be in PRECIOS PRODUCTOS Y SERVICIOS. This sheet also gets information from another sheet called COSTOS PRODUCTOS INTERNACIONALES which then sends the product to PUNTO DE EQUILIBRIO as well.

ok, mumps have a good night..
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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