Mostrando entradas con la etiqueta Excel. Mostrar todas las entradas
Mostrando entradas con la etiqueta Excel. Mostrar todas las entradas
martes, 28 de diciembre de 2010
domingo, 24 de octubre de 2010
Desordenar una columna de valores en Excel
Sub Desordenar() Dim rango As Range Set rango = Selection.Cells For i = 1 To rango.Rows.Count Dim aleatorio As Integer Dim cadena As String rango.Rows(i).Select cadena = ActiveCell.FormulaR1C1 aleatorio = Int(Rnd() * rango.Rows.Count) + 1 rango.Rows(i).FormulaR1C1 = rango.Rows_
(aleatorio).FormulaR1C1 rango.Cells(aleatorio).FormulaR1C1 = cadena Next End Sub
jueves, 4 de diciembre de 2008
VBA Excel: Brain Training
Sub InventarOperaciones()
Dim i As Integer
Dim NumOperaciones As Integer
Dim operacion As String
NumOperaciones = 10
For i = 1 To NumOperaciones
Cells(i, 1) = Int((Rnd * 10) + 1)
operacion = Int((Rnd * 3) + 1)
If operacion = "1" Then operacion = "+"
If operacion = "2" Then operacion = "-"
If operacion = "3" Then operacion = "*"
Cells(i, 2) = operacion
Cells(i, 3) = Int((Rnd * 10) + 1)
Cells(i, 4) = ""
Cells(i, 5) = ""
Next
Cells(1, 4).Select
End Sub
Sub ComprobarOperaciones()
Dim i As Integer
Dim NumOperaciones As Integer
Dim operacion As String
Dim resultado As Integer
Dim puntos As Integer
NumOperaciones = 10
puntos = 0
For i = 1 To NumOperaciones
operacion = Cells(i, 2)
If operacion = "+" Then resultado = Cells(i, 1) + Cells(i, 3)
If operacion = "-" Then resultado = Cells(i, 1) - Cells(i, 3)
If operacion = "*" Then resultado = Cells(i, 1) * Cells(i, 3)
If Cells(i, 4) = resultado Then
Cells(i, 5) = "OK"
puntos = puntos + 1
Else
Cells(i, 5) = resultado
End If
Next
MsgBox "PUNTOS:" & puntos
End Sub
jueves, 20 de noviembre de 2008
Excel VBA: Crear tablas de multiplicar
Sub Prueba()
For i = 1 To 10
For j = 1 To 10
Range(Cells(i, j), Cells(i, j)).Select
ActiveCell.FormulaR1C1 = i & "x" & j & "=" & i * j
Next
Next
End Sub
martes, 19 de agosto de 2008
Calcular la edad de una persona
En Excel
Siendo A2 el lugar donde está la fecha de nacimiento.
En Access
En un módulo se pone este código.
Ya se puede usar en las consultas.
Siendo A2 el lugar donde está la fecha de nacimiento.
=AÑO(HOY())-AÑO(A2)-1 + (MES(HOY())>MES(A2)) + (MES(A2)=MES(HOY()))*(DIA(HOY())>=DIA(A2))En Access
En un módulo se pone este código.
Function Edad (FechaNacimiento As Variant) As Integer
Dim miEdad As Variant
If IsNull(FechaNacimiento) then Edad = 0: Exit Function
miEdad = DateDiff("yyyy", FechaNacimiento, Now)
If Date < DateSerial(Year(Now), Month(FechaNacimiento)_
, Day(FechaNacimiento)) Then
miEdad = miEdad - 1
End If
Edad = CInt(miEdad)
End Function
Ya se puede usar en las consultas.
Suscribirse a:
Entradas (Atom)