Si uso un for i = 1 to 1000
, como uso el Cell.Find
función para buscar el valor de i
en mi hoja?
Necesito verificar si alguno de los números del 1 al 1000 está en la hoja (o fila ... no importa). Preferiblemente usando el bucle for.
He hecho lo siguiente:
Dim i As Integer
For i = 1 To 10
Cells.Find(What:="i", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _, SearchFormat:=False).Activate
Next i
End Sub
Respuestas
0 para la respuesta № 1Si solo hay una instancia de i
entonces encontrar podría funcionar para usted.
Sub UsingFind()
Dim i As Integer, c As Range
For i = 1 To 1000
Set c = Cells.Find(what:=i, lookat:=xlWhole)
If Not c Is Nothing Then
c.Font.Bold = 1
Else: "MsgBox "Not Found"
End If
Next i
End Sub
Si hay más de una instancia de i
entonces habría que usar algo más, como recorrer cada celda.
Por ejemplo(x
se utiliza en lugar de i
)
Sub MoreThanOne()
Dim x As Integer, c As Range, rng As Range
Set rng = Cells.SpecialCells(xlCellTypeConstants, 23)
For x = 1 To 1000
For Each c In rng.Cells
If c = x Then
c.Font.Bold = 1
End If
Next c
Next x
End Sub