You are on page 1of 10

Sub prueba()

Dim hj As Worksheet
Dim contExiste As Integer
Dim busqueda As Range
Dim res, consulta As String
Dim aa As String
Dim maquina As String
Dim shift As String
Dim line As String
Dim contramedida As String
Dim numorden, FECHA As String
Dim causaraiz As String
Dim tiempo As String
Dim responsable As String
Dim JUAN As Integer
Dim ultimaFila As Long
Dim ultimaFilaAuxiliar As Long
Dim cont As Long
Dim palabraBusqueda As String

palabraBusqueda = Sheets("Hoja5").Cells(2, 12)

palabraBusqueda = "*" & palabraBusqueda & "*"


ultimaFila = Sheets("Hoja1").Range("F" & Rows.Count).End(xlUp).Row

If ultimaFila < 2 Then


Exit Sub
End If

JUAN = "4"
res = ""
consulta = Sheets("hoja5").Cells(2, 12)
If consulta = "" Then
Exit Sub
End If

'If consulta = "j" Then

'Else
'JUAN = "2"
'End If

Select Case consulta


Case "j"
JUAN = "11"
Case "fin_forming"

Case "EDU"
JUAN = "11"
Case "audi"
Case "May"
JUAN = "2"
End Select

For Each hj In ThisWorkbook.Worksheets


With hj.UsedRange

Set busqueda = .Cells.Find(what:=consulta)

If Not busqueda Is Nothing Then


If hj.Name <> "Hoja5" Then

ultimaFila = hj.Range("C" & Rows.Count).End(xlUp).Row

If ultimaFila < 2 Then


Exit Sub
End If
For cont = 2 To ultimaFila
If hj.Cells(cont, JUAN) Like palabraBusqueda Then
FECHA = hj.Cells(cont, 2)
shift = hj.Cells(cont, 3)
maquina = hj.Cells(cont, 4)
line = hj.Cells(cont, 5)
numorden = hj.Cells(cont, 6)
causaraiz = hj.Cells(cont, 7)
tiempo = hj.Cells(cont, 10)
responsable = hj.Cells(cont, 11)
contramedida = hj.Cells(cont, 12)

ultimaFilaAuxiliar = Sheets("Hoja5").Range("C" &


Rows.Count).End(xlUp).Row
Sheets("Hoja5").Cells(ultimaFilaAuxiliar + 1, 2) = FECHA
Sheets("Hoja5").Cells(ultimaFilaAuxiliar + 1, 3) = line
Sheets("Hoja5").Cells(ultimaFilaAuxiliar + 1, 4) = maquina
Sheets("Hoja5").Cells(ultimaFilaAuxiliar + 1, 5) = line
Sheets("Hoja5").Cells(ultimaFilaAuxiliar + 1, 6) = numorden
Sheets("Hoja5").Cells(ultimaFilaAuxiliar + 1, 7) = causaraiz
Sheets("Hoja5").Cells(ultimaFilaAuxiliar + 1, 8) = tiempo
Sheets("Hoja5").Cells(ultimaFilaAuxiliar + 1, 9) = responsable
Sheets("Hoja5").Cells(ultimaFilaAuxiliar + 1, 10) = contramedida

End If
Next
res = res & vbCrLf & hj.Name
contExiste = 1

Set busqueda = .FindNext(busqueda)


End If
End If
End With

Next

If contExiste = 0 Then
MsgBox ("dato no existe")
MsgBox JUAN
Else
res = "dato encontrado en las hojas" & vbCrLf & res
MsgBox res
MsgBox JUAN
End If

Call prueba2

End Sub
HOJA FINAL

Sub prueba2()

Dim hj As Worksheet

Dim contExiste As Integer

Dim busqueda As Range

Dim res, consulta As String

Dim aa As String

Dim maquina As String

Dim shift As String

Dim line As String

Dim contramedida As String

Dim numorden, FECHA As String

Dim causaraiz As String

Dim tiempo As String

Dim responsable As String

Dim JUAN As Integer

Dim ultimaFila As Long

Dim ultimaFilaAuxiliar As Long


Dim cont As Long

Dim palabraBusqueda As String

palabraBusqueda = Sheets("Hoja6").Cells(2, 12)

palabraBusqueda = "*" & palabraBusqueda & "*"

ultimaFila = Sheets("Hoja1").Range("F" & Rows.Count).End(xlUp).Row

If ultimaFila < 2 Then

Exit Sub

End If

JUAN = "4"

res = ""

consulta = Sheets("hoja6").Cells(2, 12)

If consulta = "" Then

Exit Sub

End If

'If consulta = "j" Then

'Else

'JUAN = "2"
'End If

Select Case consulta

Case "1"

JUAN = "5"

Case "2"

JUAN = "5"

End Select

For Each hj In ThisWorkbook.Worksheets

With hj.UsedRange

Set busqueda = .Cells.Find(what:=consulta)

If Not busqueda Is Nothing Then

If hj.Name = "Hoja5" Then

ultimaFila = hj.Range("C" & Rows.Count).End(xlUp).Row

If ultimaFila < 2 Then

Exit Sub

End If
For cont = 2 To ultimaFila

If hj.Cells(cont, JUAN) Like palabraBusqueda Then

FECHA = hj.Cells(cont, 2)

shift = hj.Cells(cont, 3)

maquina = hj.Cells(cont, 4)

line = hj.Cells(cont, 5)

numorden = hj.Cells(cont, 6)

causaraiz = hj.Cells(cont, 7)

tiempo = hj.Cells(cont, 8)

responsable = hj.Cells(cont, 9)

contramedida = hj.Cells(cont, 10)

ultimaFilaAuxiliar = Sheets("Hoja6").Range("C" &


Rows.Count).End(xlUp).Row

Sheets("Hoja6").Cells(ultimaFilaAuxiliar + 1, 2) = FECHA

Sheets("Hoja6").Cells(ultimaFilaAuxiliar + 1, 3) = line

Sheets("Hoja6").Cells(ultimaFilaAuxiliar + 1, 4) = maquina

Sheets("Hoja6").Cells(ultimaFilaAuxiliar + 1, 5) = line

Sheets("Hoja6").Cells(ultimaFilaAuxiliar + 1, 6) = numorden

Sheets("Hoja6").Cells(ultimaFilaAuxiliar + 1, 7) = causaraiz

Sheets("Hoja6").Cells(ultimaFilaAuxiliar + 1, 8) = tiempo

Sheets("Hoja6").Cells(ultimaFilaAuxiliar + 1, 9) = responsable
Sheets("Hoja6").Cells(ultimaFilaAuxiliar + 1, 10) = contramedida

End If

Next

res = res & vbCrLf & hj.Name

contExiste = 1

Set busqueda = .FindNext(busqueda)

End If

End If

End With

Next

If contExiste = 0 Then

MsgBox ("dato no existe")

MsgBox JUAN

Else

res = "dato encontrado en las hojas" & vbCrLf & res

MsgBox res

MsgBox JUAN

End If

End Sub

You might also like