Hi again!
I got it!!
This is the code:
Private Sub cmdOK_Click()
Dim CveRFC$, NomDen$
'Abrimos el Catálogo de Clientes
Sheets("CC").Visible = True
ActiveWorkbook.Sheets("CC").Activate
ActiveWindow.DisplayGridlines = False
'Asignamos el nombre CveRFC al valor del campo txtRFC
CveRFC = txtRFC.Value
'Asignamos el nombre NomDen al valor del campo txtNombre
NomDen = txtNombre.Value
If optBuscaRFC = True Then
'Iniciamos la búsqueda por RFC
Call BuscarRFC(CveRFC, NomDen)
Else
'Iniciamos la búsqueda por nombre
Call BuscarNombre(NomDen)
End If
Unload Me
Sheets("CC").Visible = False
Sheets("Detalle").Activate
End Sub
Private Sub BuscarRFC(CveRFC As String, NomDen As String)
Dim RFCIni$, RFCFin$, frstMatch$
Dim CveClisRFC$, NomClisRFC$, ClaveRFC$
Dim ResponseRFC%
RFCIni = "$D$7"
Range(RFCIni).Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
RFCFin = ActiveCell.Offset(-1, 0).Address
'Establecemos nuestro rango de búsqueda e iniciamos con la operación
ActiveWorkbook.Names.Add Name:="RanBusqRFC", RefersToR1C1:=Range(RFCIni, RFCFin)
Application.GoTo Reference:="RanBusqRFC"
On Error GoTo NotFound
Selection.Find(What:=CveRFC, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False).Activate
frstMatch = ActiveCell.Address
'Si el RFC que ingresamos existe en nuestro catálogo, comenzamos a informar de los
'resultados
Do
With ActiveCell
CveClisRFC = .Offset(0, -3).Value
NomClisRFC = UCase(.Offset(0, -1).Value)
ClaveRFC = UCase(.Value)
End With
ResponseRFC = MsgBox("Nombre: " & NomClisRFC & vbCrLf & "R.F.C.: " & ClaveRFC, _
vbYesNo + vbQuestion, "¿Es correcto?")
If ResponseRFC = vbYes Then
MsgBox "La clave del cliente es: " & CveClisRFC, vbInformation, "Tome nota..."
Exit Sub
End If
Selection.Find(What:=CveRFC, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False).Activate
Loop Until ActiveCell.Address = frstMatch
MsgBox "La entrada no arrojó resultados satisfactorios", vbCritical, _
"Búsqueda fallida"
Exit Sub
'Pero si no encontramos nada informamos de ello
NotFound:
MsgBox "La clave de R.F.C. que ingresó no existe", vbCritical, _
"R.F.C. no existe"
Exit Sub
End Sub
Thanks everyone!!
Claudio C.
Bookmarks