Está en la página 1de 7

Módulo1 - 1

Sub TALLER_6_UNI_2_punto_1()

' TALLER_6_UNI_2 Macro Punto 1

Dim n As Integer

Dim mensaje As String

Dim v As Integer

mensaje = InputBox("Dime un numero", "Ejercicio 1")

n = Val(mensaje)

For n = 1 To n Step 1

v = n

Hoja1.Cells(n, 1) = v

Next n

End Sub

Sub TALLER_6_UNI_2_punto_2()

' TALLER_6_UNI_2 Macro Punto 2

Dim n As Integer

Dim mensaje As String

Dim v As Integer

mensaje = InputBox("Dime un numero", "Ejercicio 2")

n = Val(mensaje)

For n = 2 To n Step 2

v = n

Hoja1.Cells(n, 2) = v

Next n

End Sub

Sub TALLER_6_UNI_2_punto_3()

Dim n As Integer
Dim mensaje As String
Dim v As Integer
mensaje = InputBox("Dime un numero", "Ejercicio 3")
n = Val(mensaje)

suma = 0
For n = 1 To n Step 1

suma = suma + n

'Hoja1.Cells(n, 3) = suma

Next n

promedio = suma / (n - 1)

Hoja1.Cells(1, 3) = suma

End Sub

Sub TALLER_6_UNI_2_punto_4()

Dim n As Integer
Dim mensaje As String
Módulo1 - 2

Dim v As Integer
mensaje = InputBox("Dime un numero", "Ejercicio 4")
n = Val(mensaje)

suma = 0
For n = 1 To n Step 1

suma = suma + n

'Hoja1.Cells(n, 1) = suma

Next n

promedio = suma / (n - 1)

Hoja1.Cells(1, 4) = suma
Hoja1.Cells(1, 4) = n
Hoja1.Cells(1, 4) = promedio

End Sub

Sub TALLER_6_UNI_2_punto_5()

n = InputBox("Dime un numero", "Ejercicio 5")

x = 0
For i = 2 To n - 1
If n Mod i - 0 Then
x = 1
End If
Next i

If x = 0 Then
MsgBox "el numero es primo"
Else
MsgBox "el numero NO es primo"
End If

End Sub

Sub TALLER_6_UNI_2_punto_6()
Dim n, factorial As Long

factorial = 1
mensaje = InputBox("Dime un numero", "Ejercicio 6")
n = Val(mensaje)

If n < 0 Then
MsgBox "NO tiene factorial"
Else

Do While n > 1
factorial = factorial * n

n = n - 1
Loop

Cells(1, 6) = factorial

End If

End Sub

Sub TALLER_6_UNI_2_punto_7()

Dim palabra As String


Dim tamaño As Integer
Dim i As Integer
Dim contar As Integer

palabra = InputBox("Dime una palabra", "Ejercicio 7")


tamaño = Len(palabra)

For i = 1 To tamaño
If Mid(palabra, i, 1) = "a" Then
contar = contar + 1
End If
Módulo1 - 3

If Mid(palabra, i, 1) = "e" Then


contar = contar + 1
End If

If Mid(palabra, i, 1) = "i" Then


contar = contar + 1
End If

If Mid(palabra, i, 1) = "o" Then


contar = contar + 1
End If

If Mid(palabra, i, 1) = "u" Then


contar = contar + 1
End If

Next

Cells(1, 7) = "el numero de vocales es:" & contar

End Sub

Sub TALLER_6_UNI_2_punto_8()

Dim palabra As String


Dim tamaño As Integer
Dim i As Integer
Dim contar As Integer

palabra = InputBox("Dime una palabra", "Ejercicio 8")


tamaño = Len(palabra)

For i = 1 To tamaño
If Mid(palabra, i, 1) = "b" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "c" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "d" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "f" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "g" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "h" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "j" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "k" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "l" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "m" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "n" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "ñ" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "p" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "q" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "r" Then
Módulo1 - 4

contar = contar + 1
End If
If Mid(palabra, i, 1) = "s" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "t" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "v" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "w" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "x" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "y" Then
contar = contar + 1
End If
If Mid(palabra, i, 1) = "z" Then
contar = contar + 1
End If

Next

Cells(1, 8) = "el numero de letras es:" & contar

End Sub

Sub TALLER_6_UNI_2_punto_9()

Dim stringchain As String


Dim number_vector() As String
Dim desired_length As Long
desired_length = 9

stringchain = InputBox("Introduce 10 numeros separados por -. Ej. 1-2-3-4", "Ejercicio 9")

number_vector() = Split(stringchain, "-")

If UBound(number_vector) = desired_length Then

counter = -1

For iRw = 0 To UBound(number_vector)

If ((IsNumeric(number_vector(iRw))) And (IsEmpty(number_vector(iRw)) = False)) Then

counter = counter + 1

Else

MsgBox ("El caracter " & number_vector(iRw) & " no es un numero o esta vacio")

End If

Next iRw

If counter = UBound(number_vector) Then

max_number = -9999
Position = -1

For iRw = 0 To UBound(number_vector)

If ((IsNumeric(number_vector(iRw))) And (IsEmpty(number_vector(iRw)) = False)) Then

vector_int = CInt(number_vector(iRw))

If vector_int > max_number Then

max_number = vector_int

Position = iRw

End If
Módulo1 - 5

End If

Next iRw

MsgBox ("El mayor numero esta en la posicion " & CStr(Position + 1) & " con el valor " & CStr(m
ax_number))

End If

Else

MsgBox ("No hay 10 numeros...Intente de nuevo")

End If

End Sub

Sub TALLER_6_UNI_2_punto_10()

Dim stringchain As String


Dim number_vector() As String
Dim desired_length As Long

desired_length = 9

stringchain = InputBox("Introduce 10 numeros separados por -. Ej. 1-2-3-4", "Ejercicio 10")

number_vector() = Split(stringchain, "-")

If UBound(number_vector) = desired_length Then

counter = -1

For iRw = 0 To UBound(number_vector)

If ((IsNumeric(number_vector(iRw))) And (IsEmpty(number_vector(iRw)) = False)) Then

counter = counter + 1

Else

MsgBox ("El caracter " & number_vector(iRw) & " no es un numero o esta vacio")

End If

Next iRw

If counter = UBound(number_vector) Then

max_number = -9999
Position = -1

For iRw = 0 To UBound(number_vector)

If ((IsNumeric(number_vector(iRw))) And (IsEmpty(number_vector(iRw)) = False)) Then

vector_int = CInt(number_vector(iRw))

Debug.Print vector_int Mod 2

If ((vector_int > max_number) And (vector_int Mod 2 = 0)) Then

max_number = vector_int

Position = iRw

End If

End If

Next iRw

MsgBox ("El mayor numero esta en la posicion " & CStr(Position + 1) & " con el valor "
& CStr(max_number))

End If
Módulo1 - 6

Else

MsgBox ("No hay 10 numeros...Intente de nuevo")

End If

End Sub
Sub TALLER_6_UNI_2_punto_11()

Dim stringchain As String


Dim number_vector() As String
Dim desired_length As Long

desired_length = 9

stringchain = InputBox("Introduce 10 numeros separados por -. Ej. 1-2-3-4", "Ejercicio 11")

number_vector() = Split(stringchain, "-")

If UBound(number_vector) = desired_length Then

counter = -1

For iRw = 0 To UBound(number_vector)

If ((IsNumeric(number_vector(iRw))) And (IsEmpty(number_vector(iRw)) = False)) Then

counter = counter + 1

Else

MsgBox ("El caracter " & number_vector(iRw) & " no es un numero o esta vacio")

End If

Next iRw

If counter = UBound(number_vector) Then

suma = 0

For iRw = 0 To UBound(number_vector)

If ((IsNumeric(number_vector(iRw))) And (IsEmpty(number_vector(iRw)) = False)) Then

vector_int = CInt(number_vector(iRw))

If vector_int Mod 2 = 0 Then

suma = suma + vector_int

End If

End If

Next iRw

MsgBox ("La suma de los numeros pares es: " & CStr(suma))

End If

Else

MsgBox ("No hay 10 numeros...Intente de nuevo")

End If

End Sub

Sub TALLER_6_UNI_2_punto_12()

Dim stringchain As String


Dim number_vector() As String
Dim desired_length As Long

desired_length = 9
Módulo1 - 7

stringchain = InputBox("Introduce 10 numeros separados por -. Ej. 1-2-3-4", "Ejercicio 12")

number_vector() = Split(stringchain, "-")

If UBound(number_vector) = desired_length Then

counter = -1

For iRw = 0 To UBound(number_vector)

If ((IsNumeric(number_vector(iRw))) And (IsEmpty(number_vector(iRw)) = False)) Then

counter = counter + 1

Else

MsgBox ("El caracter " & number_vector(iRw) & " no es un numero o esta vacio")

End If

Next iRw

If counter = UBound(number_vector) Then

suma = 0

For iRw = 0 To UBound(number_vector)

If ((IsNumeric(number_vector(iRw))) And (IsEmpty(number_vector(iRw)) = False)) Then

vector_int = CInt(number_vector(iRw))

If vector_int Mod 2 <> 0 Then

suma = suma + vector_int

End If

End If

Next iRw

MsgBox ("La suma de los numeros inpares es: " & CStr(suma))

End If

Else

MsgBox ("No hay 10 numeros...Intente de nuevo")

End If

End Sub

También podría gustarte