macro para buscar un dato
Publicado por Jaime (2 intervenciones) el 17/11/2008 17:58:18
Este es el codigo pero necesito que en el ELSE si la celda2(celda2 es una variable) es igual a falso que me deje hacer otras cosas pero con el metodo find solo coge el valor Verdadero nose si sera por que tengo valores en blanco.
Sub GrabaryRestarA1HOJA1()
Dim celda1 As String
celda1 = Hoja1.Cells(62, 2)
Dim celda2 As String
celda2 = Range("A3:A59").Select
Selection.Find(What:=celda1, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
If celda2 = "Verdadero" Then
fila = ActiveCell.Row
columna = ActiveCell.Column
Hoja1.Cells(fila, columna + 2) = Hoja1.Cells(fila, columna + 2) - Hoja1.Cells(68, 2)
i = 2
Do While Hoja36.Cells(i, 1) <> ""
i = i + 1
Loop
Hoja36.Cells(i, 1) = Hoja1.Cells(66, 2)
Hoja36.Cells(i, 2) = Hoja1.Cells(67, 2)
Hoja36.Cells(i, 3) = Hoja1.Cells(68, 2)
Hoja36.Cells(i, 4) = Hoja1.Cells(69, 2)
Hoja36.Cells(i, 5) = Hoja1.Cells(70, 2)
Hoja36.Cells(i, 6) = Hoja1.Cells(71, 2)
Hoja36.Cells(i, 7) = Hoja1.Cells(72, 2)
Else
MsgBox ("ERROR, POR FAVOR INTRODUZCA BIEN LOS DATOS")
End If
Dim My_Range As String
On Error Resume Next 'enables error handling
My_Range = ("A66:B72")
If Len(My_Range) > 0 Then Range(My_Range).PrintOut
If Err > 0 Then MsgBox "Name or range specified is not valid."
Hoja1.Cells(62, 2) = ""
Hoja1.Cells(68, 2) = ""
Hoja1.Cells(69, 2) = ""
Hoja1.Cells(70, 2) = ""
Hoja1.Cells(72, 2) = ""
End Sub
Sub GrabaryRestarA1HOJA1()
Dim celda1 As String
celda1 = Hoja1.Cells(62, 2)
Dim celda2 As String
celda2 = Range("A3:A59").Select
Selection.Find(What:=celda1, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
If celda2 = "Verdadero" Then
fila = ActiveCell.Row
columna = ActiveCell.Column
Hoja1.Cells(fila, columna + 2) = Hoja1.Cells(fila, columna + 2) - Hoja1.Cells(68, 2)
i = 2
Do While Hoja36.Cells(i, 1) <> ""
i = i + 1
Loop
Hoja36.Cells(i, 1) = Hoja1.Cells(66, 2)
Hoja36.Cells(i, 2) = Hoja1.Cells(67, 2)
Hoja36.Cells(i, 3) = Hoja1.Cells(68, 2)
Hoja36.Cells(i, 4) = Hoja1.Cells(69, 2)
Hoja36.Cells(i, 5) = Hoja1.Cells(70, 2)
Hoja36.Cells(i, 6) = Hoja1.Cells(71, 2)
Hoja36.Cells(i, 7) = Hoja1.Cells(72, 2)
Else
MsgBox ("ERROR, POR FAVOR INTRODUZCA BIEN LOS DATOS")
End If
Dim My_Range As String
On Error Resume Next 'enables error handling
My_Range = ("A66:B72")
If Len(My_Range) > 0 Then Range(My_Range).PrintOut
If Err > 0 Then MsgBox "Name or range specified is not valid."
Hoja1.Cells(62, 2) = ""
Hoja1.Cells(68, 2) = ""
Hoja1.Cells(69, 2) = ""
Hoja1.Cells(70, 2) = ""
Hoja1.Cells(72, 2) = ""
End Sub
Valora esta pregunta


0