Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
#70403
Boa tarde!

Estou tentado criar um código VBA que recorte o telefone da coluna B, cole na coluna I e posteriormente exclua a linha que o telefone estava inserido.

Esta planilha é retirada da base de dados da minha empresa e a célula vem mesclada. Já criei um VBA que formata a planilha e a deixa exatamente como está o modelo em anexo.

Nem todas as planilhas são do tamanho do arquivo em anexo, então o ideal é criar um loop de repetição, porém o que estou fazendo está dando erro (segue o código abaixo).

Sub telefone()

Application.ScreenUpdating = False

linha = 3
linha_colar = 2

While Cells(linha, 2) <> ""
If Cells(linha, 2) <> "" Then
Cells(linha, 2).Select
Selection.Cut
If Cells(linha_colar, 9) = "" Then
Cells(linha_colar, 9).Select
ActiveSheet.Paste
End If
End If

linha = linha + 2
linha_colar = linha_colar + 2

Wend

Application.ScreenUpdating = True

End Sub
Você não está autorizado a ver ou baixar esse anexo.
Editado pela última vez por stefanordc em 22 Abr 2022 às 14:53, em um total de 1 vez.
#70404
Veja se resulta assim:
Código: Selecionar todos
Sub MovePhoneNumber()

    Dim StartLin As Long
    Dim iRow As Long
    
    Dim lRow As Long
    Dim WsD As Worksheet
    
    Set WsD = Worksheets("Planilha1")
    lRow = WsD.Cells(Rows.Count, 1).End(xlUp).Row \ 2 + 2
    
    StartLin = 3
    
    For iRow = StartLin To lRow
    
        WsD.Cells(iRow - 1, 9) = WsD.Cells(iRow, 2).Value
        WsD.Range(WsD.Cells(iRow, 1), WsD.Cells(iRow, 8)).Delete Shift:=xlUp
    Next iRow

    Set WsD = Nothing

End Sub
#70406
Deu certinho, JCabral. Muito obrigado!
Deu certinho, mano. Muito obrigado!

JCabral escreveu: 22 Abr 2022 às 13:29 Veja se resulta assim:
Código: Selecionar todos
Sub MovePhoneNumber()

    Dim StartLin As Long
    Dim iRow As Long
    
    Dim lRow As Long
    Dim WsD As Worksheet
    
    Set WsD = Worksheets("Planilha1")
    lRow = WsD.Cells(Rows.Count, 1).End(xlUp).Row \ 2 + 2
    
    StartLin = 3
    
    For iRow = StartLin To lRow
    
        WsD.Cells(iRow - 1, 9) = WsD.Cells(iRow, 2).Value
        WsD.Range(WsD.Cells(iRow, 1), WsD.Cells(iRow, 8)).Delete Shift:=xlUp
    Next iRow

    Set WsD = Nothing

End Sub
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord