Excel - array en varias hojas y ejecutar macro

 
Vista:
Imágen de perfil de OCTAVIO

array en varias hojas y ejecutar macro

Publicado por OCTAVIO (7 intervenciones) el 06/09/2022 00:13:50
Buenas tardes a todos
espero me puedan ayudar
necesito correr una macro en un conjunto de hojas, no en todas las hojas de mi libro.,
no se mucho de esto, mas me compartieron este código
solo que este código trabaja en todas las hojas del libro, yo necesito que solo trabaje en un grupo determinado de hojas,
como la puedo ajustar para que haga eso?
me pueden ayudar?

anexo macro que me compartieron

Sub Dosomething()
Dim xSh As Worksheet
Application.ScreenUpdating = False
For Each xSh In Worksheets
xSh.Select
Call RunCode
Next
Application.ScreenUpdating = True
End Sub
Sub RunCode()
'your code here
End Sub

Saludos.. y gracias de antemano a todos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Antoni Masana
Val: 4.908
Oro
Ha mantenido su posición en Excel (en relación al último mes)
Gráfica de Excel

array en varias hojas y ejecutar macro

Publicado por Antoni Masana (2477 intervenciones) el 06/09/2022 19:07:29
Te pongo tres posibles soluciones en función de donde este el filtro.

SOLUCIÓN - A

Poniendo la lista de hojas a tratar:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Sub Dosomething()
    Dim xSh As Worksheet
    Application.ScreenUpdating = False
    For Each xSh In Worksheets
        If xSh.name = "..." or xSh.name = "..." or xSh.name = "..." Then
            xSh.Select
            Call RunCode
        End If
    Next
    Application.ScreenUpdating = True
End Sub
 
Sub RunCode()
    'your code here
End Sub


SOLUCIÓN - B

Poniendo la lista de hojas a ignorar:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Sub Dosomething()
    Dim xSh As Worksheet
    Application.ScreenUpdating = False
    For Each xSh In Worksheets
        If xSh.name <> "..." And xSh.name <> "..." And xSh.name <> "..." Then
            xSh.Select
            Call RunCode
        End If
    Next
    Application.ScreenUpdating = True
End Sub
 
Sub RunCode()
    'your code here
End Sub


SOLUCIÓN - C

Poniendo el filtro en el valor de una celda, la misma en todas las hojas:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Sub Dosomething()
    Dim xSh As Worksheet
    Application.ScreenUpdating = False
    For Each xSh In Worksheets
        xSh.Select
        If Range("..") = "..." Then
            Call RunCode
        End If
    Next
    Application.ScreenUpdating = True
End Sub
 
Sub RunCode()
    'your code here
End Sub

Saludos.
\\//_
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar