I have this code
Sub search()
Dim dato As String
Dim filallibre As String
dato = InputBox("Type 1 Or 2?")
filalibre = Sheets(dato).Range("A65000").End(xlUp).Row + 1
If dato = "" Then Exit Sub
Set buscado = ActiveSheet.Range("A1:A" & Range("A65000").End(xlUp).Row).Find(dato, LookIn:=xlValues, lookat:=xlWhole)
If Not buscado Is Nothing Then
ubica = buscado.Address
Do
buscado.EntireRow.Copy Destination:=Sheets(dato).Cells(filalibre, 1)
filalibre = filalibre + 1
Set buscado = ActiveSheet.Range("A1:A" & Range("A65000").End(xlUp).Row).FindNext(buscado)
Loop While Not buscado Is Nothing And buscado.Address <> ubica
End If
End Sub
I am getting error in my code when I run the macro, it works fine when I type "1" but when y put "2" it does the job which is moving the rows to the worksheet named "2" but it doesn't stops, seems like it stays looping until i press Esc then the message box with the error appears, the error appears to be in the line
Loop While Not buscado Is Nothing And buscado.Address <> ubica
how can i Solve this?
EDIT [6/7]
thanks a lot for your suggestions, I've tried some of your suggestions and seems like either i'm too noob for this VBA level or there is something completely wrong with my code, here I is the link to my excel file if anyone wants to test it and see if you can find the problem
Basically what the file does when I run the macro with Ctrl+Shift+K, is to ask as for either "1" or "2" then it identifies which rows have 1 or 2 in the column A and move those rows to the sheet 1 or 2 depending of what number I entered in the input box, it works well with "1" but not with "2"
Loop While buscado.Address <> ubica.Option Explicitat the top of every module. The Variable you are using inDim filallibre As Stringandfilalibre = Sheets(dato).Range("A65000").End(xlUp).Row + 1are not the same, not to mention you declared it as a string but are using it as a long.