Private Sub cmdOK_Click()
'
'Opening sheet
Sheets("CC").Visible = True
ActiveWorkbook.Sheets("CC").Activate
ActiveWindow.DisplayGridlines = False
'setting variables
Dim CveRFC As String
CveRFC = txtRFC.Value
'Set NomDen to txtNombre textbox
Dim NomDen As String
NomDen = txtNombre.Value
If optBuscaRFC = True Then
'Starting RFC search
Dim RFCIni As String
RFCIni = "$D$7"
Dim RFCFin As String
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
'Now we set my search range
ActiveWorkbook.Names.Add Name:="RanBusqRFC", RefersToR1C1:=Range(RFCIni, RFCFin)
Application.Goto Reference:="RanBusqRFC"
Set BuskRFC = Selection.Find(What:=CveRFC, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
'If RFC (or part of the RFC) I put in the textbox doesn't exist in my range I exit from search
If Not BuskRFC Is Nothing Then
BuskRFC.Activate
Dim CveClisRFC As String
CveClisRFC = (ActiveCell.Offset(0, -3).Value)
Dim NomClisRFC As String
NomClisRFC = UCase(ActiveCell.Offset(0, -1).Value)
Dim ClaveRFC As String
ClaveRFC = UCase(ActiveCell.Value)
'I notify whose is the RFC
MsgBox "Name: " & NomClisRFC & Chr(13) & "R.F.C.: " _
& ClaveRFC, vbInformation, "Searching goals"
Dim ResponseRFC
ResponseRFC = MsgBox("¿Is that right?", vbYesNo + vbQuestion, "Checking information")
If ResponseRFC = vbYes Then
MsgBox "Personal ID is: " & CveClisRFC, vbInformation, "Pay attention..."
Sheets("CC").Visible = False
Sheets("Detalle").Activate
Exit Sub
Else
'HERE I NEED SOMETHING TO CONTINUE UNTIL I FIND WHAT I'M SEARCHING OR UNTIL THE SEARCHING GOES BACK TO THE FIRST ADDRESS FOUND
Unload Me
Sheets("CC").Visible = False
Sheets("Detalle").Activate
Exit Sub
End If
Else
'If I don't find nothing I send the error message
Unload Me
MsgBox "R.F.C. you put doesn't exist", vbCritical, _
"R.F.C. doesn't exist"
Sheets("CC").Visible = False
Sheets("Detalle").Activate
Exit Sub
End If
Else
'Starting name search
Dim NomIni As String
NomIni = "$C$7"
Dim NomFin As String
Range(NomIni).Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
NomFin = ActiveCell.Offset(-1, 0).Address
'Set the searching range
ActiveWorkbook.Names.Add Name:="RanBusqNom", _
RefersToR1C1:=Range(NomIni, NomFin)
Application.Goto Reference:="RanBusqNom"
Set BuskNom = Selection.Find(What:=NomDen, After:=ActiveCell, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
'If the name I put doesn't exist I exit
If Not BuskNom Is Nothing Then
BuskNom.Activate
Dim CveClisNom As String
CveClisNom = (ActiveCell.Offset(0, -2).Value)
Dim NomClisNom As String
NomClisNom = UCase(ActiveCell.Value)
Dim RFCsNom As String
RFCsNom = UCase(ActiveCell.Offset(0, 1).Value)
MsgBox "Name: " & NomClisNom & Chr(13) & "R.F.C.: " & _
RFCsNom, vbInformation, "Searching goals"
Dim ResponseNom
ResponseNom = MsgBox("¿Is that right?", vbYesNo + vbQuestion, "Checking information")
If ResponseNom = vbYes Then
MsgBox "Personnal ID is: " & CveClisNom, _
vbInformation, "Pay attention..."
Sheets("CC").Visible = False
Sheets("Detalle").Activate
Exit Sub
Else
'HERE I NEED SOMETHING TO CONTINUE UNTIL I FIND WHAT I'M SEARCHING OR UNTIL THE SEARCHING GOES BACK TO THE FIRST ADDRESS FOUND
Unload Me
Sheets("CC").Visible = False
Sheets("Detalle").Activate
Exit Sub
End If
End If
End If
End Sub
Bookmarks