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
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,197
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
 

Forum statistics

Threads
1,081,530
Messages
5,359,347
Members
400,524
Latest member
Excelbat

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top