Jump to content
Fórum Script Brasil
  • 0

Loop - For each sheet in worksheet


Question

Bom dia pessoal,

 

Estou precisando de um help. Quero fazer um loop para passar por todas as abas e realizar a substituição, porém ele só está realizando na aba selecionada e não em todas, poderiam me falar o que está incorreto no meu código por favor?

Sub Cabecalho()
Dim ws As Worksheet
For Each ws In Worksheets
    Rows("1:2").Select
    Selection.Replace What:="Budget_2021\Budget_2021\[Template BGT 2021.xlsx", _
        Replacement:="Budget_2022\Budget_2022\[Template BGT 2022.xlsx", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
Next
End Sub

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Bom dia @leoamsousa!

Tenta da seguinte maneira:

Sub Cabecalho()
Dim ws As Worksheet
For Each ws In Worksheets
	ws.select
    Rows("1:2").Select
    Selection.Replace What:="Budget_2021\Budget_2021\[Template BGT 2021.xlsx", _
        Replacement:="Budget_2022\Budget_2022\[Template BGT 2022.xlsx", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
Next
End Sub

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      149264
    • Total Posts
      645605
×
×
  • Create New...