MACROS
Y termina con la instrucción
End Sub.
Sub Primero
Range("A1").Value = "Hola"
End Sub
Range("A1").Value="Hola"
WorkSheets(1).Range("A1").Value = "Hola"
Sub Primero
ActiveSheet.Range("A1").Value = "Hola"
End Sub
Sub Primero
ActiveSheet.ActiveCell.Value = "Hola"
End Sub
Sub PrimeroApplication.WorkBooks(1).WorkSheets(1).Range("A1").Value = "Hola"
End Sub
Sub Segundo
ActiveSheet.Range("A1").Value = "Hola"
ActiveSheet.Range("A1").Font.Bold = True
ActiveSheet.Range("A1").Font.Color = RGB(255,0,0)
End Sub
Sub Segundo
ActiveSheet.Range("A1:A8").Value = "Hola"
ActiveSheet.Range("A1:A8").Font.Bold = True
ActiveSheet.Range("A1:A8").Font.Color =RGB(255,0,0)
End Sub
DIM variable AS tipo.
La Función InputBox.
InputBox(Mensaje, Título, Valor por defecto)
Sub Entrar_Valor
Dim Texto As String
Texto = InputBox("Introducir un texto " & Chr(13) & "Para la casilla A1", "Entrada de datos")
ActiveSheet.Range("A1").Value = Texto
End Sub
Sub Entrar_Valor
ActiveSheet.Range("A1").Value = InputBox("Introducir untexto " & Chr(13) & "Para la casilla
A1", "Entrada de datos")
End Sub
Option Explicit
Sub Entrar_Valor
Dim Casilla As String
Dim Texto As String
Casilla = InputBox("En que casilla quiere entrar el valor", "Entrar Casilla")
Texto = InputBox("Introducir un texto " & Chr(13) & "Para la casilla " & Casilla , "Entrada de
datos")
ActiveSheet.Range(Casilla).Value = Texto
End SubSub Entrar_Valor
Texto = InputBox("Introducir un texto " & Chr(13) & "Para la casilla A1", "Entrada de datos")
ActiveSheet.Range("A1").Value = Testo
End Sub
Option Explicit
Sub Entrar_Valor
Dim Texto As String
Texto = InputBox("Introducir un texto " & Chr(13) & "Para la casilla A1", "Entrada de datos")
ActiveSheet.Range("A1").Value = Testo
End Sub
Option ExplicitSub Sumar()
Dim Numero1 As Integer
Dim Numero2 As Integer
Numero1 = InputBox("Entrar el primer valor", "Entrada de datos")
Numero2 = InputBox("Entrar el primer valor", "Entrada de datos")
ActiveSheet.Range("A1").Value = Numero1 + Numero2
End Sub
Option Explicit
Sub Sumar()
Dim Numero1 As Integer
Dim Numero2 As Integer
Numero1 = Val(InputBox("Entrar el primer valor", "Entradade datos"))
Numero2 = Val(InputBox("Entrar el primer valor", "Entrada de datos"))
ActiveSheet.Range("A1").Value = Numero1 + Numero2
End Sub
Val(Cadena). Convierte la cadena a un valor numérico.
Str(Número). Convierte el número a una expresión cadena.
Objeto Cells(fila, columna).
ActiveSheet.Cells(1,1).Value="Hola"
Range(Cells(1, 1), Cells(8, 2)).Value = "Hola"Range("A5:B10").Cells(2, 1).Value = "Hola"
Estructuras condicionales.
If Condición Then
Senténcia1
Senténcia2
.
.
SenténciaN
End If
Sub Condicional()
ActiveSheet.Range("A1").Value = 0 ActiveSheet.Range("A2").Value = 0
ActiveSheet.Range("A3").Value = 0
ActiveSheet.Range("A1").Value = Val(InputBox("Entrar el precio", "Entrar"))
If ActiveSheet.Range("A1").Value > 1000 ThenActiveSheet.Range("A2").Value = Val(InputBox("Entrar Descuento", "Entrar"))
End If
ActiveSheet.Range("A3").Value = ActiveSheet.Range("A1").Value - _
ActiveSheet.Range("A2").Value
End Sub
Option Expl icit
Sub Condicional()
Dim Precio As Integer
Dim Descuento As Integer
Precio = 0
Descuento = 0
Precio = Val(InputBox("Entrar el precio", "Entrar"))
IfPrecio > 1000 Then
Descuento = Val(InputBox("Entrar Descuento", "Entrar"))
End If
ActiveSheet.Range("A1").Value = Precio
ActiveSheet.Range("A2").Value = Descuento
ActiveSheet.Range("A3").Value = Precio - Descuento
End Sub
Macro que compara los valores de las casillas A1 y A2 de la hoja activa. Si son iguales pone el color de la
fuente de ambas en azul.
Sub Condicional2()
If...
Regístrate para leer el documento completo.