• No se han encontrado resultados

Módulo V Cuadros y Hojas de Diálogo

ANEXO 1. EJERCICIOS DE EXCEL AVANZADO

Crear una macro que capture MATRICULA, NOMBRE, PUESTO y SUELDO del trabajador y los coloque al final de una lista, y al terminar nos regrese a la primera celda de la hoja.

Procedimiento:

Nombre de la Macro: Macro_Ejercicio1

Secuencia de grabación:

1. F5 - A1 - Enter 2. FIN 

3. TECLEAR MATRICULA - Enter ( "1" ) 4. TECLEAR NOMBRE - Enter ( "JUAN" ) 5.  TECLEAR PUESTO - Enter ( "MATEMATICO" ) 6. TECLEAR SUELDO - Enter ( "10000" ) 7. F5 - A1 - Enter

8. Detener Grabación

Código Visual Basic:

Sub MACRO_EJERCICIO1( )

Application.Goto Reference:="R1C1"

Selection.End(xlDown).Select

ActiveCell.Offset(1, 0).Range("A1").Select

ActiveCell.FormulaR1C1 = “1”

ActiveCell.Offset(0, 1).Range("A1").Select

ActiveCell.FormulaR1C1 = “JUAN”

ActiveCell.Offset(0, 1).Range("A1").Select

ActiveCell.FormulaR1C1 = “MATEMATICO”

ActiveCell.Offset(0, 1).Range("A1").Select

ActiveCell.FormulaR1C1 = “10000”

Application.Goto Reference:="R1C1"

End Sub

Codigo Visual Basic Modificado:

El código ya modificado con la instrucción InputBox de Visual Basic queda de la forma siguiente:

Sub MACRO_EJERCICIO1()

Application.Goto Reference:="R1C1" Selection.End(xlDown).Select

ActiveCell.Offset(1, 0).Range("A1").Select

MATRI = InputBox("TECLEA MATRÍCULA DEL TRABAJADOR") ActiveCell.FormulaR1C1 = MATRI

ActiveCell.Offset(0, 1).Range("A1").Select

NOMBRE = InputBox("TECLEA NOMBRE DEL TRABAJADOR") ActiveCell.FormulaR1C1 = NOMBRE

ActiveCell.Offset(0, 1).Range("A1").Select

PUESTO = InputBox("TECLEA PUESTO DEL TRABAJADOR") ActiveCell.FormulaR1C1 = PUESTO

ActiveCell.Offset(0, 1).Range("A1").Select

SUELDO = InputBox("TECLEA SUELDO DEL TRABAJADOR") ActiveCell.FormulaR1C1 = SUELDO

Application.Goto Reference:="R1C1" End Sub

EJERCICIO 2:

Crear una macro para capturar MATRÍCULA, NOMBRE, CATEGORIA, SUELDO, NIVEL ACADEMICO Y EDO. CIVIL del trabajador en el rango de B2:B7, después copiar estos datos y colocarlos al final de la lista.

Procedimiento:

Nombre de Macro: "Macro_Ejercicio2"

Nota: Antes de proceder al grabado de la macro deberá definirse un nombre de rango para los datos capturados B2:B7): "DATOS1"

Secuencia de grabación:

1. F5 - A1 - Enter

2.   TECLEAR MATRICULA - Enter ( "1" ) 3.  - TECLEAR NOMBRE - Enter ( "JUAN" ) 4.  - TECLEAR CATEGORIA - Enter ( "52" ) 5.  - TECLEAR SUELDO - Enter ( "9800" ) 6.  - TECLEAR NIVEL ACADÉMICO - Enter

( "LICENCIATURA" )

7.  - TECLEAR ESTADO CIVIL - Enter ( "CASADO" )

8. F5 - DATOS_1 - Enter

(DATOS_1 es el nombre de rango B2:B7 definido previamente)

9. Edición > Copiar (CTRL+C) 10. F5 - A9 - Enter

11. FIN  

12. Edición > Pegado Especial

 Valores  Transponer Aceptar. 13. ESC

Código Visual Basic:

Sub MACRO_EJERCICIO2() Application.Goto Reference:="R1C1" ActiveCell.Offset(1, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "1" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "JUAN" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "N52" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "9800" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "LICENCIATURA" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "CASADO" Application.Goto Reference:="DATOS_1" Selection.Copy Application.Goto Reference:="R9C1" Selection.End(xlDown).Select ActiveCell.Offset(1, 0).Range("A1").Select

Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=True

Application.CutCopyMode = False Application.Goto Reference:="R1C1" End Sub

Código Visual Basic modificado:

El código ya modificado con la instrucción InputBox de Visual Basic queda de la forma siguiente:

Sub MACRO_EJERCICIO2()

Application.Goto Reference:="R1C1" ActiveCell.Offset(1, 1).Range("A1").Select NOMBRE = InputBox("TECLEA EL NOMBRE") ActiveCell.FormulaR1C1 = NOMBRE

ActiveCell.Offset(1, 0).Range("A1").Select

MATRICULA = InputBox("TECLEA LA MATRICULA") ActiveCell.FormulaR1C1 = MATRICULA

ActiveCell.Offset(1, 0).Range("A1").Select

CATEGORIA = InputBox("TECLEA CATEGORIA O NIVEL") ActiveCell.FormulaR1C1 = NIVEL

ActiveCell.Offset(1, 0).Range("A1").Select SUELDO = InputBox("TECLEA EL SUELDO") ActiveCell.FormulaR1C1 = SUELDO

ActiveCell.Offset(1, 0).Range("A1").Select

NIVEL_ACADEMICO=InputBox("TECLEA NIVEL ACADEMICO") ActiveCell.FormulaR1C1 = NIVEL_ACADEMICO ActiveCell.Offset(1, 0).Range("A1").Select ESTADO_CIVIL = InputBox("TECLEA ESTADO CIVIL") ActiveCell.FormulaR1C1 = ESTADO_CIVIL Application.Goto Reference:="DATOS_1" Selection.Copy Application.Goto Reference:="R9C1" Selection.End(xlDown).Select ActiveCell.Offset(1, 0).Range("A1").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=True

Application.CutCopyMode = False

ActiveCell.Offset(0, 1).Range("A1").Select Application.Goto Reference:="R1C1" End Sub

EJERCICIO 3:

Crear una macro para generar una factura. La macro genera el número consecutivo de la factura; limpia los datos del cliente anterior y todos los productos que se llevó; luego, pide el Nombre del Cliente, así como su Dirección. Enseguida ingresa el nombre del producto, el precio, la cantidad, y realiza operaciones para calcular el subtotal, el IVA y Total, y los suma al total a pagar. Al final este total a pagar lo acumula en un total global.

PROCEDIMIENTO:

Nombre de Macro: "Macro_Ejercicio3"

Nota: Antes de proceder al grabado de la macro deberá hacer lo siguiente:

 Definir un nombre para el rango B4:B5 ("CLIENTE") que corresponde a los datos del cliente y otro para el rango A8:F15 (“PRODUCTOS”) correspondiente a los productos vendidos.

 Para el registro de fecha y hora en que se emite la factura colocar en B2 la función =HOY() y en D2 la función =AHORA() con formato de hora.

 Para generar el consecutivo de la factura colocar un número 1 en la celda F1.  Para el cálculo del total de la factura colocar en F16 la formula: =SUMA(F8:F15)

SECUENCIA DE GRABACIÓN:

1. F5 - A1 - Enter 2. F5 - CLIENTE - Enter 3. SUPR 4. F5 - PRODUCTOS - Enter 5. SUPR 6. F5 - F1 - Enter 7. CTRL+C

8.  Edición > Pegado Especial  Valores  Sumar – Aceptar 9. ESC

10. F5 - B4 - Enter

11. TECLEA NOMBRE CLIENTE - Enter 12.  TECLEA DIRECCION

CLIENTE - Enter 13. F5 - A6 – Enter

14. FIN 

15. TECLEAR ARTÍCULO - Enter 16.  TECLEAR PRECIO - Enter 17.  TECLEAR CANTIDAD - Enter 18.  =  *  Enter 19.  =  * 0.15 Enter 20.  =  +  Enter 21. F5 - F16 - Enter 22. CTRL+C 23. F5 - H3 - Enter

24. Edición > Pegado Especial  Valores  Sumar Aceptar 25. ESC

26. F5 - A1 – Enter 27. Detener Grabación

Código Visual Basic:

Sub MACRO_EJERCICIO3() Application.Goto Reference:="R1C1" Application.Goto Reference:="CLIENTE" Selection.ClearContents Application.Goto Reference:="PRODUCTOS" Selection.ClearContents Application.Goto Reference:="R1C6" Selection.Copy ActiveCell.Offset(1, 0).Range("A1").Select

Selection.PasteSpecial Paste:=xlValues, Operation:=xlAdd, SkipBlanks _ :=False, Transpose:=False

Application.CutCopyMode = False Application.Goto Reference:="R4C2" ActiveCell.FormulaR1C1 = "JUAN LEON" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "TLALPAN 23" Application.Goto Reference:="R6C1" Selection.End(xlDown).Select ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "BALATAS" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "4" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "50" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=RC[-2]*RC[-1]" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=RC[-1]*15%" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]" Application.Goto Reference:="R16C6" Selection.Copy Application.Goto Reference:="R3C8"

Selection.PasteSpecial Paste:=xlValues, Operation:=xlAdd, SkipBlanks _ :=False, Transpose:=False

Application.CutCopyMode = False Application.Goto Reference:="R1C1" End Sub

Código Visual Basic modificado:

El código ya modificado con la instrucción InputBox de Visual Basic queda de la forma siguiente:

Sub MACRO_EJERCICIO3() Application.Goto Reference:="R1C1" Application.Goto Reference:="CLIENTE" Selection.ClearContents Application.Goto Reference:="PRODUCTOS" Selection.ClearContents Application.Goto Reference:="R1C6" Selection.Copy ActiveCell.Offset(1, 0).Range("A1").Select

Selection.PasteSpecial Paste:=xlValues, Operation:=xlAdd, SkipBlanks _ :=False, Transpose:=False

Application.CutCopyMode = False Application.Goto Reference:="R4C2"

CLIENTE = InputBox("TECLEA EL NOMBRE DEL CLIENTE") ActiveCell.FormulaR1C1 = CLIENTE

ActiveCell.Offset(1, 0).Range("A1").Select

DIRECCION = InputBox("TECLEA DIRECCION DEL CLIENTE") ActiveCell.FormulaR1C1 = DIRECCION

Application.Goto Reference:="R6C1" Selection.End(xlDown).Select

ActiveCell.Offset(1, 0).Range("A1").Select PRODUCTO = InputBox("TECLEA EL PRODUCTO") ActiveCell.FormulaR1C1 = PRODUCTO

ActiveCell.Offset(0, 1).Range("A1").Select CANTIDAD = InputBox("TECLEA LA CANTIDAD") ActiveCell.FormulaR1C1 = CANTIDAD

ActiveCell.Offset(0, 1).Range("A1").Select PRECIO = InputBox("TECLEA EL PRECIO") ActiveCell.FormulaR1C1 = PRECIO ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=RC[-2]*RC[-1]" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=RC[-1]*15%" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]" Application.Goto Reference:="R16C6" Selection.Copy Application.Goto Reference:="R3C8"

Selection.PasteSpecial Paste:=xlValues, Operation:=xlAdd, SkipBlanks _

:=False, Transpose:=False Application.CutCopyMode = False Application.Goto Reference:="R1C1" End Sub

EJERCICIO 4:

Crear una macro que nos pida MATRICULA, NOMBRE, PUESTO y SUELDO del trabajador y los coloque al final de la lista, y que al terminar nos pregunte si deseamos seguir capturando mas datos, si contestamos que si, entonces que nos pida nuevamente los datos para capturar, pero si contestamos que no, que termine la macro.

Consulte la figura del Ejercicio 1

PROCEDIMIENTO:

Nombre de la Macro: Macro_Ejercicio4

El procedimiento de grabación y código son similares al ejercicio 1 como a continuación observamos: Nota: Antes de proceder al grabado de la macro

deberá definirse un nombre de rango para los datos capturados (B2:B7): "DATOS_2"

SECUENCIA DE GRABACIÓN:

1. F5 - A1 - Enter 2. FIN 

3. TECLEAR MATRICULA - Enter ( "1" ) 4. TECLEAR NOMBRE - Enter ( "JUAN" ) 5.  TECLEAR PUESTO - Enter ( "MATEMATICO" ) 6. TECLEAR SUELDO - Enter ( "10000" ) 7. F5 - A1 – Enter

8. Detener Grabación

Código Visual Basic:

Sub MACRO_EJERCICIO4( ) Application.Goto Reference:="R1C1" Selection.End(xlDown).Select ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = “1” ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = “JUAN” ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = “MATEMATICO” ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = “10000” Application.Goto Reference:="R1C1" End Sub

Código Visual Basic modificado:

El código deberá modificarse con las instrucciones InputBox, Do While y MsgBox quedando de la forma siguiente:

Sub MACRO_EJERCICIO1() RESPUESTA = vbYes

Do While RESPUESTA = vbYes

Application.Goto Reference:="R1C1" Selection.End(xlDown).Select

ActiveCell.Offset(1, 0).Range("A1").Select

MATRI = InputBox("TECLEA MATRÍCULA DEL TRABAJADOR") ActiveCell.FormulaR1C1 = MATRI

ActiveCell.Offset(0, 1).Range("A1").Select

NOMBRE = InputBox("TECLEA NOMBRE DEL TRABAJADOR") ActiveCell.FormulaR1C1 = NOMBRE

ActiveCell.Offset(0, 1).Range("A1").Select

PUESTO = InputBox("TECLEA PUESTO DEL TRABAJADOR") ActiveCell.FormulaR1C1 = PUESTO

ActiveCell.Offset(0, 1).Range("A1").Select

SUELDO = InputBox("TECLEA SUELDO DEL TRABAJADOR") ActiveCell.FormulaR1C1 = SUELDO

RESPUESTA = MsgBox("¿DESEAS CAPTURAR MAS DATOS?", vbYesNo)

Loop

Application.Goto Reference:="R1C1" End Sub

EJERCICIO 5:

Crear una macro que nos pida MATRICULA, NOMBRE, CATEGORIA, SUELDO, NIVEL ACADEMICO y ESTADO CIVIL del trabajador y los coloque en el rango B2:B7, luego que nos pida comprobar si están bien los datos, si están mal que los vuelva a pedir, si están bien que los copie y los coloque al final de la lista, y al terminar nos pregunte si deseamos seguir capturando mas datos, si contestamos que si, que nos pida nuevamente los datos para capturar, pero si contestamos que no, que termine la macro.

PROCEDIMIENTO:

Nombre de la Macro: Macro_Ejercicio5

El procedimiento de grabación y código son similares al ejercicio 2 como a continuación observamos: Nota: Antes de proceder al grabado de la macro deberá definirse

un nombre de rango para los datos capturados (B2:B7): "DATOS_2"

SECUENCIA DE GRABACIÓN:

1. F5 - A1 - Enter

2.  TECLEAR MATRICULA - Enter ( "1" ) 3.  -TECLEAR NOMBRE - Enter ( "JUAN" ) 4.  -TECLEAR CATEGORIA - Enter ( "52" ) 5.  -TECLEAR SUELDO - Enter ( "9800" ) 6.  -TECLEAR NIVEL ACADÉMICO - Enter

( "LICENCIATURA" )

7.  - TECLEAR ESTADO CIVIL - Enter ( "CASADO" )

8. F5 - DATOS_1 – Enter

(DATOS_1 es el nombre de rango B2:B7 definido previamente)

9. Edición > Copiar (CTRL+C) 10. F5 - A9 - Enter

11. FIN  

12. Edición > Pegado Especial

 Valores  Transponer Aceptar. 13. ESC

14. F5 - A1 - Enter 15. Detener Grabación

Código Visual Basic

Sub MACRO_EJERCICIO5() Application.Goto Reference:="R1C1" ActiveCell.Offset(1, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "1" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "JUAN" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "52" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "9800" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "LICENCIATURA" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "CASADO" Application.Goto Reference:="DATOS_2" Selection.Copy Application.Goto Reference:="R9C1" Selection.End(xlDown).Select ActiveCell.Offset(1, 0).Range("A1").Select

Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=True

Application.CutCopyMode = False Application.Goto Reference:="R1C1"

Código Visual Basic modificado

El código deberá modificarse con las instrucciones InputBox, Do While y MsgBox quedando de la forma siguiente:

Sub MACRO_EJERCICIO5()

RESPUESTA1 = vbYes

Do WhileRESPUESTA1 = vbYes

RESPUESTA2 = vbNo

Do WhileRESPUESTA2 = vbNo

Application.Goto Reference:="R1C1" ActiveCell.Offset(1, 1).Range("A1").Select NOMBRE = InputBox("TECLEA EL NOMBRE") ActiveCell.FormulaR1C1 = NOMBRE

ActiveCell.Offset(1, 0).Range("A1").Select

MATRICULA = InputBox("TECLEA LA MATRICULA") ActiveCell.FormulaR1C1 = MATRICULA

ActiveCell.Offset(1, 0).Range("A1").Select

CATEGORIA = InputBox("TECLEA LA CATEGORIA O NIVEL") ActiveCell.FormulaR1C1 = NIVEL

ActiveCell.Offset(1, 0).Range("A1").Select SUELDO = InputBox("TECLEA EL SUELDO") ActiveCell.FormulaR1C1 = SUELDO

ActiveCell.Offset(1, 0).Range("A1").Select

NIVEL_ACADEMICO = InputBox("TECLEA EL NIVEL ACADEMICO") ActiveCell.FormulaR1C1 = NIVEL_ACADEMICO

ActiveCell.Offset(1, 0).Range("A1").Select

ESTADO_CIVIL = InputBox("TECLEA EL ESTADO CIVIL") ActiveCell.FormulaR1C1 = ESTADO_CIVIL

RESPUESTA2 = MsgBox("¿TUS DATOS SON CORRECTOS?", vbYesNo)

Loop Application.Goto Reference:="DATOS_2" Selection.Copy Application.Goto Reference:="R9C1" Selection.End(xlDown).Select ActiveCell.Offset(1, 0).Range("A1").Select

Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=True

Application.CutCopyMode = False

RESPUESTA1 = MsgBox("¿DESEAS CAPTURAR MAS DATOS?", vbYesNo)

Loop

ActiveCell.Offset(0, 1).Range("A1").Select Application.Goto Reference:="R1C1" End Sub

EJERCICIO 6:

Crear una macro para llenar esta factura. La macro genera el número consecutivo de la factura; limpia los datos del cliente anterior y todos los productos que se llevó; luego, pide el nombre del cliente, así como su dirección. luego nos pide comprobar si los datos del cliente son correctos, si están mal que nos vuelva a pedir los datos, si están bien que avance para ingresar el nombre del PRODUCTO, el PRECIO, la CANTIDAD, y realiza operaciones para calcular el SUBTOTAL, el IVA y TOTAL, al llegar al total individual nos pregunte si deseamos mas productos para este cliente, si contestamos que si, que nos vuelva a pedir producto, precio y cantidad, si contestamos que no los suma al total a pagar. Al final este total a pagar lo acumula en un total global.

PROCEDIMIENTO:

Nombre de Macro: "Macro_Ejercicio6"

El procedimiento de grabación y código son similares al ejercicio 3 como a continuación observamos: Nota: Antes de proceder al grabado de la macro deberá hacer lo siguiente

Definir un nombre para el rango B4:B5 ("CLIENTE_2") que corresponde a los datos del cliente y otro para el rango A8:F15 (“PRODUCTOS_2”) correspondiente a los productos vendidos.

Para el registro de fecha y hora en que se emite la factura colocar en B2 la función =HOY() y en D2 la función =AHORA() con formato de hora.

Para generar el consecutivo de la factura colocar un número 1 en la celda F1. Para el cálculo del total de la factura colocar en F16 la formula: =SUMA(F8:F15)

SECUENCIA DE GRABACIÓN:

1. F5 - A1 - Enter 2. F5 - F1 - Enter 3. CTRL+C

4.  Edición > Pegado Especial  Valores  Sumar – Aceptar 5. ESC 6. F5 - PRODUCTOS - Enter 7. SUPR 8. F5 - CLIENTE - Enter 9. SUPR 10. F5 - B4 - Enter

11. TECLEA NOMBRE CLIENTE - Enter 12.  TECLEA DIRECCION

CLIENTE - Enter 13. F5 - A6 – Enter

14. FIN 

15. TECLEAR ARTÍCULO - Enter 16.  TECLEAR PRECIO - Enter 17.  TECLEAR CANTIDAD - Enter 18.  =  *  Enter 19.  =  * 0.15 Enter 20.  =  +  Enter 21. F5 - F16 - Enter 22. CTRL+C 23. F5 - H3 - Enter

24. Edición > Pegado Especial

 Valores Sumar Aceptar 25. ESC

26. F5 - A1 - Enter

Código Visual Basic

Sub MACRO_EJERCICIO6() Application.Goto Reference:="R1C1" Application.Goto Reference:="R1C6" Selection.Copy ActiveCell.Offset(1, 0).Range("A1").Select

Selection.PasteSpecial Paste:=xlValues, Operation:=xlAdd, SkipBlanks _

:=False, Transpose:=False Application.CutCopyMode = False Application.Goto Reference:="PRODUCTOS_2" Selection.ClearContents Application.Goto Reference:="CLIENTE_2" Selection.ClearContents Application.Goto Reference:="R4C2" ActiveCell.FormulaR1C1 = "JUAN LEON" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "TLALPAN 23" Application.Goto Reference:="R6C1" Selection.End(xlDown).Select ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "BALATAS" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "4" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "50" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=RC[-2]*RC[-1]" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=RC[-1]*15%" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]" Application.Goto Reference:="R16C6" Selection.Copy Application.Goto Reference:="R3C8"

Selection.PasteSpecial Paste:=xlValues, Operation:=xlAdd, SkipBlanks _

:=False, Transpose:=False Application.CutCopyMode = False Application.Goto Reference:="R1C1" End Sub

Código Visual Basic Modificado

El código deberá modificarse con las instrucciones InputBox, Do While y MsgBox de la forma siguiente:

Sub MACRO_EJERCICIO6()

Application.Goto Reference:="R1C1" Application.Goto Reference:="R1C6" Selection.Copy

ActiveCell.Offset(1, 0).Range("A1").Select

Selection.PasteSpecial Paste:=xlValues, Operation:=xlAdd, SkipBlanks _

:=False, Transpose:=False Application.CutCopyMode = False

Application.Goto Reference:="PRODUCTOS_2" Selection.ClearContents

CORRECTOS = vbNo

Do While CORRECTOS = vbNo

Application.Goto Reference:="CLIENTE_2" Selection.ClearContents

Application.Goto Reference:="R4C2"

CLIENTE = InputBox("TECLEA NOMBRE DEL CLIENTE") ActiveCell.FormulaR1C1 = CLIENTE

ActiveCell.Offset(1, 0).Range("A1").Select

DIRECCION = InputBox("TECLEA DIRECCION DEL CLIENTE") ActiveCell.FormulaR1C1 = DIRECCION

CORRECTOS = MsgBox(“¿LOS DATOS SON CORRECTOS?”,vbYesNo)

Loop

RESPUESTA = vbYes

Do While RESPUESTA = vbYes

Application.Goto Reference:="R6C1" Selection.End(xlDown).Select

ActiveCell.Offset(1, 0).Range("A1").Select PRODUCTO = InputBox("TECLEA EL PRODUCTO") ActiveCell.FormulaR1C1 = PRODUCTO

ActiveCell.Offset(0, 1).Range("A1").Select CANTIDAD = InputBox("TECLEA LA CANTIDAD") ActiveCell.FormulaR1C1 = CANTIDAD

ActiveCell.Offset(0, 1).Range("A1").Select PRECIO = InputBox("TECLEA EL PRECIO") ActiveCell.FormulaR1C1 = PRECIO ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=RC[-2]*RC[-1]" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=RC[-1]*15%" ActiveCell.Offset(0, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]"

RESPUESTA = MsgBox(“¿DESEAS INGRESAR MÁS PRODUCTOS?”,vbYesNo)

Loop

Application.Goto Reference:="R16C6" Selection.Copy

Application.Goto Reference:="R3C8"

Selection.PasteSpecial Paste:=xlValues, Operation:=xlAdd, SkipBlanks _

:=False, Transpose:=False Application.CutCopyMode = False Application.Goto Reference:="R1C1" End Sub

ANEXO 2. SISTEMA DE MACROS PARA EXCEL AVANZADO

Documento similar