Ejercicios resueltos de macros (excel)

Páginas: 6 (1493 palabras) Publicado: 13 de septiembre de 2012
EJERCICIOS RESUELTOS DE MACROS
(Excel)

1.- CALCULADORA BASICA

[pic]


Private Sub CmdCerrar_Click()
End
End Sub

Private Sub CmdDivision_Click()
Cells(2, 2).Value = Val(TxtValor1.Text) / Val(TxtValor2.Text)
TxtValor1.Text = ""
TxtValor2.Text = ""
TxtValor1.SetFocus
End Sub

Private Sub CmdMas_Click()
Cells(2, 2).Value = Val(TxtValor1.Text) + Val(TxtValor2.Text)TxtValor1.Text = ""
TxtValor2.Text = ""
TxtValor1.SetFocus
End Sub

Private Sub CmdMenos_Click()
Cells(2, 2).Value = Val(TxtValor1.Text) - Val(TxtValor2.Text)
TxtValor1.Text = ""
TxtValor2.Text = ""
TxtValor1.SetFocus
End Sub

Private Sub CmdProducto_Click()
Cells(2, 2).Value = Val(TxtValor1.Text) * Val(TxtValor2.Text)
TxtValor1.Text = ""
TxtValor2.Text = ""
TxtValor1.SetFocus
End Sub2.- INGRESO DE DATOS A TRAVES DE UN FORMULARIO


[pic]

Private Sub CmdAceptar_Click()
If TxtApellidos.Text = "" Or TxtDireccion.Text = "" Or TxtEdad.Text = "" Then
MsgBox "Faltan llenar Datos"
TxtApellidos.SetFocus
Else
For i = 3 To 65536
If Cells(i, 1) = "" Then
Exit For
End If
Next
Cells(i, 1).Value = TxtApellidos.Text
Cells(i, 2).Value =TxtDireccion.Text
Cells(i, 3).Value = TxtEdad.Text
Cells(i + 1, 1).Select ' esta línea es para que se active la siguiente celda, se pinta el contorno
TxtApellidos.Text = ""
TxtDireccion.Text = ""
TxtEdad.Text = ""
TxtApellidos.SetFocus
End If
End Sub

Private Sub CmdCerrar_Click()
End
End Sub

3.- INGRESO DE CLIENTES AL INICIO

[pic]
El siguiente código va en un modulo
SubAuto_open() ' Con el nombre de este procedimiento se activa automaticamente dicho formulario
' con solo abrir el libro
Load UserForm1
UserForm1.Show
End Sub

‘Codigo del formulario

Private Sub CmdConsultas_Click()
Cells.Find(what:=TxtNombres, after:=ActiveCell).Activate
ActiveCell.Offset(0, 1).Select
TxtDireccion = ActiveCell
ActiveCell.Offset(0, 1).Select
TxtTelefono= ActiveCell
End Sub



' Dicho formulario, hace busquedas con solo una porcion de texto

Private Sub CmdEliminar_Click()
Selection.EntireRow.Delete ' elimina el renglon o fila, que en ese momento esta seleccionado
Range("b7").Select
TxtNombres = Empty
TxtDireccion = Empty
TxtTelefono = Empty
TxtNombres.SetFocus
End Sub

Private Sub CmdNuevo_Click()
Range("b7").SelectRange("b7").Value = TxtNombres.Text
Range("c7").Value = TxtDireccion.Text
Range("d7").Value = TxtTelefono.Text
Selection.EntireRow.Insert ' Aqui se inserta una fila en la hoja de excel, en la celda b7
TxtNombres = Empty ' Limpia las cajas de texto
TxtDireccion = Empty
TxtTelefono = Empty
TxtNombres.SetFocus ' Pone el foco en dicha caja de texto
End Sub

Private Sub CmdSalir_Click()
EndSheets("Hoja1").Activate
Range("A1:D10").Select
ActiveCell.Value = "Hola Mundo"
ActiveCell.Offset(0, 1).ActivatePrivate Sub CommandButton1_Click()
TxtNombres = Empty
TxtDireccion = Empty
TxtTelefono = Empty
TxtNombres.SetFocus

End Sub

4.- GRAFICOS
[pic]

Sub grafica()
1 Range("A5:B10").Select
2 Charts.Add
3 ActiveChart.ChartType = xlColumnClustered
4 ActiveChart.SetSourceDataSource:=Sheets("Hoja1").Range("A5:B10"), PlotBy:= xlColumns
5 ActiveChart.Location Where:=xlLocationAsObject, Name:="Hoja1"
End Sub
 
La primer línea indica el rango donde están los datos, valores ejes y valores series,
La segunda línea indica que se agrega una grafica
La tercera línea indica el tipo de grafica que se desea
La cuarta línea indica como se acomodan los datos en la graficaLa quinta línea indica donde se muestra la grafica, si en la misma hoja o en una sola hoja.
Si queremos otros tipos de gráficos, aquí tenemos algunos modelos predefinidos:
Otros tipos de graficas tenemos:
ActiveChart.ChartType = xlColumnClustered
ActiveChart.ChartType = xlBarClustered
ActiveChart.ChartType = xlLineMarkers
ActiveChart.ChartType = xlPie
ActiveChart.ChartType = xlXYScatter...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Ejercicio resuelto excel 2003
  • Ejercicio Macros Excel
  • Ejercicios Resueltos De Macros Office 2007
  • COMPLETO CURSO DE EXCEL CON MANUALES TEÓRICOS Y EJERCICIOS RESUELTOS
  • ejercicios resueltos de macro
  • Ejercicios Resuelto Hoja De Excel
  • Ejercicios Excel Resueltos
  • Macros En Excel

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS