Ejemplo de macros de excell sencillos.
Sub Mayusculas()
Dim celda As Range
For Each celda In Selection
If Not IsEmpty(celda) Then
celda.Value = UCase(celda.Value)
End If
Next celda
End Sub
Sub Minusculas()
Dim celda As Range
For Each celda In Selection
If Not IsEmpty(celda) Then
celda.Value = LCase(celda.Value)
End If
Next celda
End Sub
Sub QuitarEspacios()
Dim celda As Range
For Each celda In Selection
If Not IsEmpty(celda) Then
celda.Value = Application.WorksheetFunction.Trim(celda.Value)
End If
Next celda
End Sub
Sub InsertarFecha()
Selection.Value = Date
End Sub
Sub InsertarHora()
Selection.Value = Time
End Sub
Sub ResaltarValores()
Dim celda As Range
For Each celda In Selection
If IsNumeric(celda.Value) Then
If celda.Value > 100 Then
celda.Interior.Color = RGB(255, 255, 0)
End If
End If
Next celda
End Sub
Sub BorrarFilasVacias()
Dim i As Long
For i = Selection.Rows.Count To 1 Step -1
If Application.WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then
Selection.Rows(i).EntireRow.Delete
End If
Next i
End Sub
Sub NuevaHoja()
Worksheets.Add.Name = "Hoja_" & Format(Now, "hhmmss")
End Sub
Sub CalcularEdad()
Dim texto As String
Dim anio As Integer
Dim mes As Integer
Dim dia As Integer
Dim anioCompleto As Integer
Dim fechaNacimiento As Date
Dim edad As Integer
' Tomar el valor de la celda F10
texto = Range("F10").Value
' Extraer año, mes y día
anio = Mid(texto, 5, 2)
mes = Mid(texto, 7, 2)
dia = Mid(texto, 9, 2)
' Determinar el siglo correcto
If anio <= Right(Year(Date), 2) Then
anioCompleto = 2000 + anio
Else
anioCompleto = 1900 + anio
End If
' Crear la fecha
fechaNacimiento = DateSerial(anioCompleto, mes, dia)
' Calcular edad
edad = Int((Date - fechaNacimiento) / 365.25)
' Mostrar resultado en una celda
Range("G10").Value = edad
End Sub