Ejecutar código excel en las dos hojas siguientes

Tengo un libro con tres hojas y este código hace su función en una sola hoja como puedo hacer para que se ejecute también en las dos hojas siguientes llamadas lotería y chance

Sub buscar_reemplazar_BORDE()
Application.ScreenUpdating = False
Dim lookup

'opcional: quitar bordes anteriores
Set DATOS = Range("A1:AA80").CurrentRegion
DATOS.Borders.LineStyle = xlNone

'se toma la selección desde el rango AI
lookup = ActiveCell.Value
'se guarda en AK1 ... Ya tiene color y formato la celda
ActiveCell.Copy
Range("AK1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False

'preparar col AR con lista de rango AM:AP
With Range("AR:AR")
.ClearContents
.NumberFormat = "@"
End With
x = Range("AM" & Rows.Count).End(xlUp).Row
finy = 2
For Z = 2 To x
nrox = Format(Range("AM" & Z) & Range("AN" & Z) & Range("AO" & Z) & Range("AP" & Z), "0000")
If InStr(1, UCase(nrox), "X", 0) = 0 Then
Range("AR" & finy) = nrox: finy = finy + 1
End If
Next Z

Set DATOS = Range("A1:AA80").CurrentRegion
Set lista = Range("AR1").CurrentRegion
MATRIZ = DATOS
With lista
For i = 2 To .Rows.Count
numeros = .Cells(i, 1)
cuenta = WorksheetFunction.CountIf(DATOS, numeros)
If cuenta > 0 Then
For j = 1 To cuenta
If j = 1 Then Set busca = DATOS.Find(Format(numeros, "0000"), lookat:=xlWhole)
If j > 1 Then Set busca = DATOS.FindNext(busca)
On Error Resume Next
Celda = busca.Address
With Range(Celda)
.BorderAround ColorIndex:=0, Weight:=xlThick
End With
Next j
Else
GoTo SIGUIENTE
End If
On Error GoTo 0
SIGUIENTE:
Next i
End With
SALIDA:
End Sub

1 respuesta

Respuesta

Yo agregaría lo. Siguiente.

Sub buscar_reemplazar_BORDE()
Application.ScreenUpdating = False
Dim lookup

Set l1= activeworkbook

For each hoja in l1

'opcional: quitar bordes anteriores
Set DATOS = Range("A1:AA80").CurrentRegion
DATOS.Borders.LineStyle = xlNone

'se toma la selección desde el rango AI
lookup = ActiveCell.Value
'se guarda en AK1 ... Ya tiene color y formato la celda
ActiveCell.Copy
Range("AK1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False

'preparar col AR con lista de rango AM:AP
With Range("AR:AR")
.ClearContents
.NumberFormat = "@"
End With
x = Range("AM" & Rows.Count).End(xlUp).Row
finy = 2
For Z = 2 To x
nrox = Format(Range("AM" & Z) & Range("AN" & Z) & Range("AO" & Z) & Range("AP" & Z), "0000")
If InStr(1, UCase(nrox), "X", 0) = 0 Then
Range("AR" & finy) = nrox: finy = finy + 1
End If
Next Z

Set DATOS = Range("A1:AA80").CurrentRegion
Set lista = Range("AR1").CurrentRegion
MATRIZ = DATOS
With lista
For i = 2 To .Rows.Count
numeros = .Cells(i, 1)
cuenta = WorksheetFunction.CountIf(DATOS, numeros)
If cuenta > 0 Then
For j = 1 To cuenta
If j = 1 Then Set busca = DATOS.Find(Format(numeros, "0000"), lookat:=xlWhole)
If j > 1 Then Set busca = DATOS.FindNext(busca)
On Error Resume Next
Celda = busca.Address
With Range(Celda)
.BorderAround ColorIndex:=0, Weight:=xlThick
End With
Next j
Else
GoTo SIGUIENTE
End If
On Error GoTo 0
SIGUIENTE:
Next i
End With

Next 
SALIDA:
End Sub

Fijate bien que lo único que agregué fue un set al principio y un for each y al final antes de salida el cierre del for each. 

Fíjate si te sirve. No.olvides valorar.

me sale error en For each hoja in l1

Este es mi correo pásamelo así lo reviso. [email protected]

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas