Search a ID Number in VBA HEEEEELP!!!

garden_rael

Board Regular
Joined
Apr 1, 2008
Messages
100
I'm trying to create a button to fill a simple form made in Excel
It should prompt the user for the account number... and then look for it in a database located in a hidden sheet in the book... if it finds it... it will put the found number on a cell and easy vlookups do the rest...

But the searching macro is driving me nuts! :confused:

This is what I have so far...

Sub TURNO()
Dim cto As String
Dim esta As String
Dim neta As Boolean
cto = InputBox("Busqueda de Contrato", "Generación de Turnos")
Application.ScreenUpdating = False
Sheets("Lista").Activate
Range("A1:A10000").Activate
If neta = IsEmpty(Cells.Find(What:=cto, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)) Then

Cells.Find(What:=cto, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

esta = ActiveCell.Value
Sheets("TURNO").Activate
Cells(1, 9).Value = esta

GoTo Final
Else
Sheets("Lista").Activate
a = MsgBox("Contrato no encontrado, verifique...")

Final:
End If
Application.ScreenUpdating = True
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Code:
Sub TURNO()
Dim cto As String, neta As Variant
cto = InputBox("Busqueda de Contrato", "Generación de Turnos")
If cto = "" Then Exit Sub
With Sheets("Lista")
Set neta = .Columns(1).Find(What:=cto, LookIn:=xlFormulas, LookAt:=xlPart)
If Not neta Is Nothing Then
Sheets("TURNO").Range("I1").Value = .Cells(neta.Row, 1).Value
Else
MsgBox ("Contrato no encontrado, verifique...")
End If
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,854
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top