Sub Depurar()
Dim Rango As Range
Dim Celda As Range
Select Case MsgBox("Esta seguro de realizar la opci�n?", vbYesNo +
vbExclamation)
Case Is = vbYes
ThisWorkbook.Save
Case Is = vbNo
Exit Sub
End Select
ultima = Cells(Rows.Count, 1).End(xlUp).Row
Set Rango = Range(Cells(1, 1), Cells(ultima, 1))
For Each Celda In Rango
If Not IsEmpty(Celda) Then
Celda = UCase(Trim(Celda)) 'LTRIM RTRIM
End If
Next Celda
End Sub
'Identifica el rango donde se encuentra un n�mero
Sub EjemploSelectCase()
numero = InputBox("Ingrese un N�mero:", "Cuadro de Texto")
Do While Not IsNumeric(numero)
MsgBox "Ingrese s�lo n�meros"
numero = InputBox("Ingrese un N�mero:", "Cuadro de Texto")
Loop
Select Case numero
Case 1 To 5
MsgBox "El n�mero esta entre 1 y 5"
Case 6, 7, 8
MsgBox "El n�mero esta entre 6, 7 y 8"
Case 9 To 10
MsgBox "El n�mero esta entre 9 y 10"
Case Else
MsgBox "El n�mero NO esta entre 1 y 10"
End Select
End Sub
'Entrega la posici�n de la letra l en el texto
Sub Ctxt()
Text = "Hola mundo"
b = "l"
p = InStr(1, Text, b, vbTextCompare)
MsgBox p
End Sub
'Entrega el largo del String
Sub Largo()
MsgBox Len("Hola Mundo")
End Sub
'Guarda y sale del libro, en caso de no guardar tambi�n sale, y para no salir hay
que presionar cancelar
Sub Guardar_Salir()
Select Case MsgBox("Desea Guardar antes de salir?", vbYesNoCancel +
vbExclamation)
Case Is = vbYes
ThisWorkbook.Save
Application.Quit
Case Is = vbNo
Application.Quit
Case Is = vbCancel
Exit Sub
End Select
End Sub
'Declaramos un vector y le asignamos la potencia al cuadrado de los n�meros desde
el 1
Sub vector()
Dim vector(5) As Integer
For i = 0 To 4
vector(i) = (i + 1) * (i + 1)
Next i
For j = 1 To 5
Cells(j, 1) = vector(j - 1)
Next j
End Sub
'Declaramos una matriz
Sub Matrices()
Dim Matriz(3, 3) As Integer
For i = 0 To 2
For j = 0 To 2
Matriz(i, j) = (i + 1) * (1 + j)
Next j
Next i
For i = 0 To 2
For j = 0 To 2
Cells(i + 1, j + 1) = Matriz(i, j)
Next j
Next i
End Sub
'Busca un texto y corrobora que se inserte por lo menos alg�n dato en el inputbox
Sub Buscar()
a = 1
j = InputBox(" Ingrese palabra a buscar:", "Texto")
Do While j = Empty
j = InputBox(" Debe ingresar texto:", "Advertencia")
Loop
UltimaFila = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To UltimaFila
If UCase(Trim(Cells(i, 1))) = Trim(UCase(j)) Then
Cells(i, 1).Select
MsgBox "Se encontr�: " & j & " en la posici�n: " & i
a = 0
End If
Next i
If a = 1 Then
MsgBox "No se encontr�: " & j
End If
End Sub
'Realiza busqueda de un dato mediante la estructura de control FOR EACH
Sub Buscar2()
Dim a As Integer
bus = Range("A1:A10")
n = InputBox("Ingrese nombre a buscar: ", "Nombre")
Do While n = Empty
n = InputBox("Ingrese nombre a buscar: ", "Advertencia")
Loop
For Each cell In bus
If cell = n Then
a = 1
End If
Next cell
If a = 1 Then
MsgBox ("Encontrado")
Else
MsgBox "�No encontr�"
End If
End Sub
'Cuenta las letras que hay en las primeras 10 celdas
Sub Busqueda()
Dim Buscar As String
Buscar = InputBox(" Ingrese letra a buscar:", "Letra")
cont = 0
For j = 1 To 10
q = 1
r = 0
lg = Len(Cells(j, 1))
For i = 1 To lg
p = InStr(q, Cells(j, 1), Buscar, vbTextCompare)
If p > r Then
r = p
cont = cont + 1
End If
q = q + 1
Next i
Next j
MsgBox cont
End Sub