Inserir Linhas e copiar fórmulas com referência outra aba

RPreviatto

New Member
Joined
Jul 24, 2023
Messages
2
Office Version
  1. 365
Com o código abaixo incluo novas linhas e copia a fórmula da linha de cima.

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.ScreenUpdating = False 'Desabilita atualização de tela
 ''ActiveSheet.Unprotect "1234" 'desbloqueia planilha
' declara as variáveis linha ei
  Dim i, linhas Como Variante
showInputBox:
    linhas = Application.InputBox("Quantas linhas você quer INCLUIR ?", Title:="Adicionar Linhas")

        
    Se linhas = Falso Então
        MsgBox ("Inclusão de linha(s) cancelada(s)!", vbOKOnly, "CANCELADO"
    ' ActiveSheet.Protect AllowFormattingCells:=True, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True, AllowFormattingRows:=True, AllowDeletingRows:=True, Password:="1234"
        ActiveSheet.EnableSelection = xlNoRestrictions
        Fim
    Outro
        Se linhas = vbNullString Então
            MsgBox ("Campo Vazio Linhas. É necessário digitar um valor!"), vbOKOnly, "Adicionar Linhas"
     ' ActiveSheet.Protect AllowFormattingCells:=True, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True, AllowFormattingRows:=True, AllowDeletingRows:=True, Password:="1234"
        ActiveSheet.EnableSelection = xlNoRestrictions

        Fim
            GoTo showInputBox
        Fim se
    Fim se
    
        Para i = 1 Para linhas
        Cancelar = Verdadeiro
 

        Target.Offset(1).EntireRow.Insert
        Target.EntireRow.Copy Target.Offset(1).EntireRow
        No Erro Retomar Avançar
        Target.Offset(1).EntireRow.SpecialCells(xlConstants).ClearContents
            
        
        Proximo eu
     ' ActiveSheet.Protect AllowFormattingCells:=True, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True, AllowFormattingRows:=True, AllowDeletingRows:=True, Password:="1234"
        ActiveSheet.EnableSelection = xlNoRestrictions
        
End Sub
[/CÓDIGO]

Ocorre que ao incluir 3 novas linhas na posição A4, as células B5, B6 e B7 não seguem a sequência pois referências as células de outra aba, no entanto as células E5, E6 e E7 estão corretas, talvez por haver fórmulas e texto(constantes)? conforme imagem Plano2.

Como resolver? sou leigo no assunto.
 

Attachments

  • Plan2.jpg
    Plan2.jpg
    44.5 KB · Views: 6

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Ocorre que ao incluir 3 novas linhas na posição A4, as células B5, B6 e B7 não seguem a sequência pois referências as células de outra aba, no entanto as células E5, E6 e E7 estão corretas, talvez por haver fórmulas e texto(constantes)? conforme imagem Plano2.

Como resolver? sou leigo no assunto.
 
Upvote 0

Forum statistics

Threads
1,215,102
Messages
6,123,097
Members
449,096
Latest member
provoking

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top