MACROS WORK WELL, BUT WHEN I DELETE THE DATA TO LEAVE THE FILE WITHOUT INFORMATION, MACROS DON'T WORK

leobrice

New Member
Joined
Jun 14, 2024
Messages
37
Office Version
  1. 2013
Platform
  1. Windows
Greetings friends of MREXCEL, good evening
The file is used to calculate costs of products and services, and the macros automate the process of calculations and procedures, apparently it works well, but when I delete all the information to start using the file, it does not work. Does not send the information from the NATIONAL PRODUCT COSTS sheet to the PRODUCTS AND SERVICES PRICES sheet
I explain how it works:
NATIONAL PRODUCT COST SHEET:
It records information on national products and services, and includes:
A= Product or Service
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 PRODUCT AND SERVICES PRICES sheet when registering the Total Purchase Amount (E).
PRICE SHEET PRODUCTS AND SERVICES:
Here the information on national products and services is recorded to calculate the price.
The information on products and services comes from the NATIONAL PRODUCT COSTS sheet and is:
A = Name of the Product or Service
B= NATIONAL.
The rest of the sheet is handled by filling out information in some columns and the rest is formula.
As I explained before, when I clear all the information to start from scratch, the macro does not work.

EXAMPLE MACRO DONT WORK.xlsm
ABCDEFG
1ABC
2COST
3PRODUCTNACIONALMEASUREQAMOUNTUNIT COST
4
5PRODUCT 1NACIONALKilo1.000,00100.000,00100,00por Kilo
6PRODUCT 2NACIONALLitro1.000,00400.000,00400,00por Litro
7PRODUCT 3NACIONALKilo1.000,00300.000,00300,00por Kilo
8PRODUCT 4NACIONALGalón1.000,00400.000,00400,00por Galón
9PRODUCT 5NACIONALKilo1.000,0040.000,0040,00por Kilo
10NACIONAL0,000
11NACIONAL0,000
12NACIONAL0,000
13NACIONAL0,000
14NACIONAL0,000
15
16
COSTOS PRODUCTOS NACIONALES
Cell Formulas
RangeFormula
F5:F14F5=IFERROR(E5/D5,0)
G5:G14G5=C5
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G5:G14Cell Value=0textNO
Cells with Data Validation
CellAllowCriteria
E5:E8Custom=CONTAR.SI($A$5:$A$14;E5)<=1
E9:E14Any value
A5:B14Custom=CONTAR.SI($A$5:$A$14;A5)<=1
C5:C14List=UNIDADES


EXAMPLE MACRO DONT WORK.xlsm
ABCDE
1ABC
2PRICE
3PRODUCTNACIONAL o IMPORTADOMEASUREUNIT COSTSALES
4
50
6PRODUCT 1NACIONALKilo100,00
7PRODUCT 2NACIONALLitro400,00
8PRODUCT 3NACIONALKilo300,00
9PRODUCT 4NACIONALGalón400,00
10PRODUCT 5NACIONALKilo40,00
11
12
13
14
15
16
PRECIOS PRODUCTOS Y SERVICIOS
Cell Formulas
RangeFormula
E5E5=SUM(E6:E14)
C6:C14C6=IFERROR(IF(B6="NACIONAL",VLOOKUP(A6,'COSTOS PRODUCTOS NACIONALES'!$A$5:$G$14,3,0),VLOOKUP(A6,#REF!,3,0))," ")
D6:D14D6=IFERROR(IF(B6="NACIONAL",VLOOKUP(A6,'COSTOS PRODUCTOS NACIONALES'!$A$5:$G$14,6,0),VLOOKUP(A6,#REF!,23,0))," ")
Cells with Data Validation
CellAllowCriteria
A10:A13Custom=CONTAR.SI($A$5:$A$14;A10)<=1
A6:B9Custom=CONTAR.SI($A$5:$A$14;A6)<=1


SHEET COST NATIONAL PRODUCTS VBA
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Me.Name = "COSTOS PRODUCTOS NACIONALES"
End Sub

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." & 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 > 5 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("C5:C" & uf)) Is Nothing And _
Application.Intersect(Target, Range("D5:D" & uf)) Is Nothing And _
Application.Intersect(Target, Range("E5: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("A5:A" & ufd).Find(prod)
pro_d.Offset(, 1) = Worksheets("COSTOS PRODUCTOS NACIONALES").Range("B" & Target.Row).Value
End With
End If


End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,224,814
Messages
6,181,125
Members
453,021
Latest member
Justyna P

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